This guide is a step-by-step guide to deploy a WebAssembly (WASM) smart contract. As a result, the output is highly optimized, which saves you gas costs.
In this tutorial, we will create a non-fungible token (NFT) and deploy it to our public testnet Dusty.
ERC721 is a standard for representing ownership of non-fungible tokens, that is, where each token is unique such as in real estate or collectibles.
During this part, we will set up a Rust environment with the latest
rustup component add rust-src --toolchain nightlyrustup target add wasm32-unknown-unknown --toolchain stable
As a pre-requisite for the tool, you need to install the binaryen package, which is used to optimize the WebAssembly bytecode of the contract. Many package managers have it available nowadays ‒ e.g., it's a package for Debian/Ubuntu, Homebrew, and Arch Linux.
After you've installed the package, execute:
cargo install cargo-contract --vers ^0.11 --force --lockedCopy to clipboardErrorCopied
You can then use
cargo contract --help to start exploring the commands made available to you.
We are going to use ink! CLI to generate the files we need for a WASM smart contract project. Make sure you are in your working directory and then run:
re in your working directory and then run:
cargo contract new erc721
This command will create a new project folder named
erc20 which we will explore:
ink! Contract Project
NFToken|+-- lib.rs <-- Contract Source Code|+-- Cargo.toml <-- Rust Dependencies and ink! Configuration
The ink CLI automatically generates the source code for a standard ink! contract. You can take a sneak peek to have a look at some code. Now, let's add some code. In this guide, we will use Visual Studio Code.
You can find our example contract here:
Just replace the code in your
lib.rs file with the complete code from our template.
You will see at the bottom of the source code there is a simple test that verifies the contract functionality. We can test this code is functioning as expected using the off-chain test environment that ink! provides.
In your project folder, run:
cargo +nightly test
To which you should see a successful test completion:
Now that we are feeling confident things are working, we can actually compile this contract to WASM.
Run the following command to compile your smart contract:
cargo +nightly contract build
Let's deploy the contract now on Plasm/Shiden or Dusty, our testnet. In this guide, I will use our testnet, 'Dusty'. To deploy your contract go to 'Developer - Contracts'. Click on 'Upload and deploy code'.
contractfile and give your bundle a name. I used 'My NFT'
After being deployed you can start mint your NFT. Those are the availble command:
That's it! Great work. Now you can send mint and send your NFT around.