Need help with ink?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

282 Stars 85 Forks Apache License 2.0 919 Commits 45 Opened issues


Parity's ink to write smart contracts

Services available


Need anything else?

Contributors list


Parity's ink! for writing smart contracts

[![linux][a1]][a2] [![codecov][c1]][c2] [![coveralls][d1]][d2] [![loc][e1]][e2] [![matrix][k1]][k2] [![discord][l1]][l2]

> squid, the ink! mascotink! is an eDSL to write WebAssembly based smart contracts using the Rust programming language. The compilation target are blockchains built on the Substrate framework.

Guided Tutorial for Beginnerscargo-contract cli tool for ink! contracts • Canvas UI for contract deployment/interaction • Talk to us on Matrix or Discord

Table of Contents

Play with It

We have a demonstration testnet running. You can request some tokens to play with from our Faucet and deploy your contracts via the Canvas UI.

The Canvas UI can also be used to deploy your contract to e.g. a Substrate chain which you run locally and execute calls there. If you want a quickstart you can use our canvas-node project ‒ a simple Substrate blockchain which is configured to include the

pallet (see How it Works for more).


A prerequisite for compiling smart contracts is to have Rust and Cargo installed. Here's an installation guide.

We recommend installing

, a CLI tool for helping setting up and managing WebAssembly smart contracts written with ink!:

cargo install cargo-contract --force

Use the

to ensure you are updated to the most recent

In order to initialize a new ink! project you can use:

cargo contract new flipper

This will create a folder

in your work directory. The folder contains a scaffold
and a
, which both contain the necessary building blocks for using ink!.

contains our hello world contract ‒ the
, which we explain in the next section.

In order to build the contract just execute these commmands in the

cargo contract build && cargo contract generate-metadata

As a result you'll get a file

. Those need to be used when deploying the contract.

Hello, World! ‒ The Flipper


contract is a simple contract containing only a single
value. It provides methods to * flip its value from
(and vice versa) and * return the current state.

Below you can see the code using the

version of ink!.
use ink_lang as ink;

#[ink::contract] mod flipper { /// The storage of the flipper contract. #[ink(storage)] pub struct Flipper { /// The single bool value. value: bool, }

impl Flipper {
    /// Instantiates a new Flipper contract and initializes `value` to `init_value`.
    pub fn new(init_value: bool) -> Self {
        Self {
            value: init_value,

    /// Flips `value` from `true` to `false` or vice versa.
    pub fn flip(&mut self) {
        self.value = !self.value;

    /// Returns the current state of `value`.
    pub fn get(&self) -> bool {

/// Simply execute `cargo test` in order to test your contract using the below unit tests.
mod tests {
    use super::*;

    fn it_works() {
        let mut flipper = Flipper::new(false);
        assert_eq!(flipper.get(), false);
        assert_eq!(flipper.get(), true);


Place this code in the

file of your flipper contract and run
cargo contract build && cargo contract generate-metadata
to build your first ink! smart contract example.


In the

folder you'll find a number of examples written in ink!.

Some of the most interesting ones:

  • delegator
    ‒ Implements cross-contract calling.
  • trait-erc20
    ‒ Defines a trait for
    contracts and implements it.
  • erc721
    ‒ An exemplary implementation of
    NFT tokens.
  • dns
    ‒ A simple
    smart contract.
  • …and more, just rummage through the folder 🙃.

To build a single example navigate to the root of the example and run:

cargo contract build && cargo contract generate-metadata

You should now have an optimized

file and a
file in the
folder of the contract.

For further information, please have a look at the Play with It section or our smart contracts workshop.

How it Works

  • Substrate's Framework for Runtime Aggregation of Modularised Entities (FRAME) contains the
    pallet, which implements an API for typical functions smart contracts need (storage, querying information about account, …).
  • The
    pallet requires smart contracts to be uploaded to the blockchain as a Wasm blob.
  • ink! is a smart contract language which targets the API exposed by
    . Hence ink! smart contracts are compiled to Wasm.
  • When executing
    cargo contract build
    an additional file
    is created. It contains information about e.g. what methods the contract provides for others to call.

ink! Macros & Attributes Overview

Entry Point

In a module annotated with

these attributes are available:

| Attribute | Where Applicable | Description | |:--|:--|:--| |

| On
definitions. | Defines the ink! storage struct. There can only be one ink! storage definition per contract. | |
| On
definitions. | Defines an ink! event. A contract can define multiple such ink! events. | |
| Applicable to ink! events. | Tells the ink! codegen to treat the ink! event as anonymous which omits the event signature as topic upon emitting. Very similar to anonymous events in Solidity. | |
| Applicate on ink! event field. | Tells the ink! codegen to provide a topic hash for the given field. Every ink! event can only have a limited number of such topic field. Similar semantics as to indexed event arguments in Solidity. | |
| Applicable to methods. | Flags a method for the ink! storage struct as message making it available to the API for calling the contract. | |
| Applicable to method. | Flags a method for the ink! storage struct as constructor making it available to the API for instantiating the contract. | |
| Applicable to ink! messages. | Allows receiving value as part of the call of the ink! message. ink! constructors are implicitly payable. | |
#[ink(selector = "..")]
| Applicable to ink! messages and ink! constructors. | Specifies a concrete dispatch selector for the flagged entity. This allows a contract author to precisely control the selectors of their APIs making it possible to rename their API without breakage. | |
#[ink(namespace = "..")]
| Applicable to ink! trait implementation blocks. | Changes the resulting selectors of all the ink! messages and ink! constructors within the trait implementation. Allows to disambiguate between trait implementations with overlapping message or constructor names. Use only with great care and consideration! | |
| Applicable to ink! implementation blocks. | Tells the ink! codegen that some implementation block shall be granted access to ink! internals even without it containing any ink! messages or ink! constructors. |

See here for a more detailed description of those and also for details on the


Trait Definitions


to define your very own trait definitions that are then implementable by ink! smart contracts. See e.g. the
contract on how to utilize it or the documentation for details.

Off-chain Testing


proc. macro enables off-chain testing. See e.g. the
contract on how to utilize those or the documentation for details.

Developer Documentation

| Crate | Docs | Description | |:--|:--|:--|

| | Language features expose by ink!. See here for a detailed description of attributes which you can use in an
. |
| | Data structures available in ink!. |
| | Low-level interface for interacting with the smart contract Wasm executor. |
| | Common API for no_std and std to access alloc crate types. |


Visit our contribution guidelines for more information.

Use the scripts provided under

directory in order to run checks on either the workspace or all examples. Please do this before pushing work in a PR.


The entire code within this repository is licensed under the Apache License 2.0. Please contact us if you have questions about the licensing of our products.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.