Skip to main content

Quick Start

This guide will cover the basics of creating a Redspot project. The barebone without plugins allows you to run tasks, compile wasm contract and run tests automatically.

Running Tasks#

To get a quick a look of what's availabe in redspot, run npx redspot in your project directory:

$ npx redspotRedspot version 0.11.4
  --config              A Redspot config file.   --help                Shows this message, or a task's help if its name is provided   --log-level           Set log levels 1-5 (default: "2")  --max-memory          The maximum amount of memory that Redspot can use.   --network             The network to connect to.   --show-stack-traces   Show stack traces.   --tsconfig            Reserved redspot argument -- Has no effect.   --verbose             Enables Redspot verbose logging   --version             Shows redspot's version. 
  check     Check whatever you need  clean     Clears the cache and deletes all artifacts  compile   Compiles the entire project, building all artifacts  console   Opens a redspot console  explorer  Start redspot explorer  help      Prints this message  run       Runs a user-defined script after compiling the project  test      Runs mocha tests  testnet   Running the test network
To get help for a specific task run: npx redspot help [task]

Create your first Redspot project:#

Use Redspot template#

Redspot provide built-in contract templates to help developers start coding their own wasm contract without knowing all details of Redspot. To start a Redspot project for erc20

npx redspot-new erc20

Once the command runs, you will see the following directory tree

+-- contracts|   +-- Cargo.lock|   +-- Cargo.toml    +-- scripts|   +-- deploy.ts+-- tests|   +-- erc20.test.ts+-- redspot.config.ts+-- package.json

Clone an existing project#

You can also clone an existing redspot project. For example, you can clone this project

And then, do yarn to build the dependencies for Redspot project, then the npx redspot command will exist in this project.

cd <project>yarnnpx redspot

Compile your contract#

Netx, taking a look at contracts/, you should find is the sample codes for a erc20 contract written in ink! with off-chain tests. For details, please refer ink!

To compile it, simply run:

npx redspot compile

You might see error like this

ERROR: Building the contract in debug mode requires an ink! version newer than `3.0.0-rc3`!An unexpected error occurred:

This is cargo-contract complaining about the ink version. To fix this, edit contracts/Cargo.toml change the ink dependency from 3.0.0-rc3 to "3.0.0-rc4. It should look like

[package]name = "erc20"version = "3.0.0-rc4"authors = ["Parity Technologies <[email protected]>"]edition = "2018"
[dependencies]ink_primitives = { version = "3.0.0-rc4", git = "", default-features = false }ink_metadata = { version = "3.0.0-rc4", git = "", default-features = false, features = ["derive"], optional = true }ink_env = { version = "3.0.0-rc4", git = "", default-features = false }ink_storage = { version = "3.0.0-rc4", git = "", default-features = false }ink_lang = { version = "3.0.0-rc4", git = "", default-features = false }

Another possible error

ERROR: Your wasm-opt version is 91, but we require a version >= 99.

To fix this, download the latest binary release for bianryen

After compilation, you should see a new dir

artifacts  └─ erc20.contracts  └─ erc20.json

artifacts/erc20.contract is the compiled contract source code to deployed to blockchain node

artifacts/erc20.json describes all the interfaces that can be used to interact with your contract which acts the same as ABI in ethereum.

Deploy your contract#

Redspot automates the deploy process, so users won't need to update the contract file themselves.

First, make sure you have started the blockchain node, here we use canvas for demo:

canvas --dev --tmp

Config endpoint in deploy.ts, this points to websocket of the blockchain node

{        ...        networks: {    development: {      endpoint: 'ws://', //       types: {},      ...    },  },}


npx redspot run scripts/deploy.ts --no-compile

Making sure add --no-compile at the end since Redspot will compile every time by default

After the contract is successfully deployed, you can get information similar to this.

Deploy successfully. The contract address:  5CqB5Mh9UdVbTE1Gt5PJfWSiCHydJaJsA31HjKGti1Z2fn78

Test your contract

npx redspot test --no-compile

The result will be looking like this

   βœ“ Assigns initial balance (9189ms)    βœ“ Transfer adds amount to destination account (23906ms)    βœ“ Transfer emits event (17993ms)    βœ“ Can not transfer above the amount (17997ms)    βœ“ Can not transfer from empty account (24001ms)

  5 passing (2m)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”β”‚          β”‚          β”‚ Min                      β”‚ Max                       β”‚ Avg                      β”‚       β”‚β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”‚ Contract β”‚ Message  β”‚ EstimateGas β”‚ Weight     β”‚ EstimateGas β”‚ Weight      β”‚ EstimateGas β”‚ Weight     β”‚ Calls β”‚β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”‚ erc20    β”‚ transfer β”‚ 4782870832  β”‚ 5280208832 β”‚ 9451855260  β”‚ 10397508443 β”‚ 7604329958  β”‚ 8280994032 β”‚ 5     β”‚β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”˜

Congrats! You now know the basic of Redspot! Let's dive deep.#