Ink! Smart Contracts
This article will show you how to deploy ink! smart contracts to the Arctic testnet.
Besides Solidity, ICE also supports writing smart contracts in Ink! , an embedded domain specific language (eDSL) for writing smart contracts in Rust. These smart contracts are compiled into WebAssembly (wasm) code, which is executed by the Contracts Pallet of the ICE blockchain.

Getting Started

Installing Prerequisites

rustup component add rust-src --toolchain nightly
rustup target add wasm32-unknown-unknown --toolchain nightly
  • Install cargo-contract, a CLI tool for setting up and managing WebAssembly smart contracts written using ink!.
cargo install cargo-contract --vers ^0.17 --force --locked
  • Install the binaryen package, which is used to optimize the WebAssembly bytecode of the contract
# For Ubuntu or Debian users
sudo apt install binaryen
# For MacOS users
brew install binaryen
NOTE: If you're unable to find a version of binaryen compatible with your OS, you can download the binary directly. You can also install the package globally using NPM.

Creating Flipper Contract

We shall create a simple “Flipper” contract, which allows users to store, retrieve and toggle a boolean value.
In your working directory, run:
cargo contract new flipper
This command will create a new project folder named flipper with the following content:
└─ <-- Contract Source Code
└─ Cargo.toml <-- Rust Dependencies and ink! Configuration
└─ .gitignore

Building the contract

  • To Compile the contract, run:
cargo +nightly contract build
After executing the above command, you should see three files inside “target/ink” folder; a Wasm binary, a metadata file (which contains the contract's ABI) and a .contract file which bundles both. This .contract file can be used to deploy your contract to a chain.
NOTE: If you get parity-scale-codec is ambiguous error while compiling the contract then update the following dependencies in your cargo.toml file.
scale-info = { version = "2", default-features = false, features = ["derive"], optional = true }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "full"]}
  • You can also run tests for the contract by executing the following command:
cargo +nightly test

Deploying the Contract

Note: To deploy Ink! contracts on ICE network, you should have Polkadot.js wallet extension installed on your browser. Further, the wallet should have enough balance to pay for the fees required during the contract deployment process.
The Ink! smart contract deployment is a two step process:
  1. 1.
    Putting your code on the blockchain
  2. 2.
    Creating an instance of your contract
With this pattern, contract code like the ERC20 standard can be put on the blockchain a single time, but instantiated any number of times, thus saving storage space on the chain.
Creating an instance of Ink! contracts on Arctic Network will create a new AccountId (a wallet/account) which will store any balance managed by the smart contract and allow users to interact with the contract. Therefore, the contract balance should be greater than the Existensial Deposit required by the Arctic Network
Head over to the PolkadotJs App to deploy the compiled flipper contract.
  • On the top Navbar, select Developer-> Contracts.
  • Select “Upload & deploy code” button.
  • On the popup, select the wallet to deploy the contract from, choose the “flipper.contract” file that was created after compiling the flipper contract, and give a proper name to the contract for display purpose.
  • Provide the parameters required by the contract’s constructor method. For the Flipper contract, you can provide the default boolean value of False. You can adjust the maximum amount of gas that you want the contract deployment process to consume.
  • Click on Deploy. Sign and send the transaction with your Polkadot.js wallet. You should see the following screen
It has two sections:
  • The “contracts” section is the actual instance of your deployed contract. You can call its read-only method get() and execute the state-changing flip() method.
  • The “code hashes” section is the reusable contract code that reside on-chain. If you want to deploy another instance of this same contract, you can do that from here with ease. All you need is to remember the hash (beginning with 0x…).