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.
Installation of cargo-contract
Create an ink! contract
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
+-- lib.rs <-- Contract Source Code
+-- Cargo.toml <-- Rust Dependencies and ink! Configuration
Contract Source Code
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.
Template ERC721 contract
You can find our example contract here:
plasmdocs/example/wasm/erc721 at master · PlasmNetwork/plasmdocs
Just replace the code in your lib.rs file with the complete code from our template.
Testing the contract
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.
Build your contract
Run the following command to compile your smart contract:
cargo +nightly contract build
Deploy your contract
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'.
Load your contractfile and give your bundle a name. I used 'My NFT'
Upload .contract file
Add PLD to keep your contract alive.
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.