Skip to main content

Ink! Environment


This guide is designed for those who are new to ink! or Wasm smart contracts in the Astar ecosystem. Before you begin, ensure your environment supports Rust.

What is ink!

Ink! is a Rust eDSL developed by Parity, that specifically targets smart contract development for Substrate’s pallet-contracts. Ink! is not reinventing a programming language, rather, adapting a subset of Rust to serve smart contract developers, specifically. If this isn't reason enough on its own to convince you to learn more about ink!, you can find many more here.

A frequently asked question when discussing Wasm is: Why use WebAssembly for smart contracts in the first place? You can find all the answers here.

Ink! Environment Setup

Rust and Cargo

Rust and Cargo are prerequisites for compiling Wasm smart contracts. The easiest way to obtain Cargo is by installing the current stable release of Rust using rustup. Installing Rust using rustup will also install cargo. On Linux and macOS systems, you can do that with the following:

curl -sSf | sh
# Configure
source ~/.cargo/env

This will download a script and start the installation. If you are using Windows, visit the Rust website and follow the instructions to install Rust. Configure source control to pull the latest stable release and add nightly + Wasm target with the following:

rustup default stable
rustup update
rustup update nightly
rustup component add rust-src
rustup component add rust-src --toolchain nightly
rustup target add wasm32-unknown-unknown --toolchain nightly

Due to a bug in cargo-contract, building contracts with rust nightly 1.70.0 or higher will fail. It is advised to use rustc v1.69.0 or older until the issue is resolved from cargo-contract side. For better dev experience it is advised to create a rust-toolchain file in the root of your project directory with following values.

channel = "1.69.0"
components = [ "rustfmt", "rust-src" ]
targets = [ "wasm32-unknown-unknown" ]
profile = "minimal"

See more here

Ink! CLI

The first and most important tool we will be installing is cargo-contract, a CLI tool for setting up and managing WebAssembly smart contracts written with ink!

As a prerequisite using older versions of ink! you may need to install the binaryen package, used to optimize WebAssembly contract bytecode.

Many package managers have it preinstalled, for example Debian/UbuntuHomebrew, and Arch Linux.

  • Using apt-get
apt-get update
apt-get -y install binaryen
  • Using apt
apt update
apt -y install binaryen

Two other dependencies need to be satisfied to link the ink! contract, for example to warn users about using APIs in a way that could lead to security issues.

cargo install cargo-dylint dylint-link

After you've installed the package, execute the following:

cargo install cargo-contract --force --locked

Use --force to ensure you are updated to the most recent cargo-contract version.

If you need to install an older version of cargo-contract use the following command by adding your desired version:

cargo install cargo-contract --force --version 1.5.1

You can then use cargo contract --help to start exploring all available commands.

Dev container

The above process can be automated by utilizing a preinstalled and preconfigured dev container.

Detailed instructions about how to use and configure a dev container can be found on swanky-dev-container Github