Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
This branch is 917 commits behind paritytech:master.

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

ink! - Parity's ink to write smart contracts

Linux Codecov Coveralls LoC
linux codecov coveralls loc

IMPORTANT NOTE: WORK IN PROGRESS! Do not expect this to be working.

ink! is an eDSL to write WebAssembly based smart contracts using the Rust programming language targeting Substrate blockchains.

For more information please visit the ink! tutorial.

Developer Documentation

ink_abi ink_core ink_model

Interaction with Substrate

Susbtrate contains the frame-contracts module, which provides a generic smart contract interface for Wasm blobs. It takes care of e.g. state rent, storage, costs, etc..

ink! is a smart contract language which targets the interface exposed by frame-contracts. As such, ink! smart contracts are compiled to Wasm.


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


For building the example smart contracts found under examples you will need to have cargo-contract installed.

cargo install --git cargo-contract --force

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

Build example contract and generate the contracts metadata

To build a single example and generate the contracts Wasm file, navigate to the root of the example smart contract and run:

cargo contract build

To generate the contract metadata (a.k.a. the contract ABI), run the following command:

cargo contract generate-metadata

You should now have an optimized <contract-name>.wasm file and an metadata.json file in the target folder of the contract.

For further information, please have a look at our smart contracts workshop.

Hello, World! - The Flipper

The Flipper contract is a simple contract containing only a single bool value that it can flip from true to false and vice versa and return the current state.

To create your own version of the flipper contract, you first need to initialize a new ink! project in your working directory.

cargo contract new flipper

Below you can see the code using the ink_lang2 version of ink!.

use ink_core::storage;
use ink_lang2 as ink;

#[ink::contract(version = "0.1.0")]
mod flipper {
    /// The storage of the flipper contract.
    struct Flipper {
        /// The single `bool` value.
        value: storage::Value<bool>,

    impl Flipper {
        /// Instantiates a new Flipper contract and initializes `value` to `init_value`.
        fn new(&mut self, init_value: bool) {

        /// Instantiates a new Flipper contract and initializes `value` to `false` by default.
        fn default(&mut self) {

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

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

    /// As in normal Rust code we are able to define tests like below.
    /// Simply execute `cargo test` in order to test your contract.
    mod tests {
        use super::*;

        fn default_works() {
            // Note that `#[ink(constructor)]` functions that above have been
            // defined as `&mut self` can be used as normal Rust constructors
            // in test mode.
            let flipper = Flipper::default();
            assert_eq!(flipper.get(), false);

        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.


Visit our contribution guidelines for more information.


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.


Rust eDSL for writing smart contracts







No releases published


No packages published


  • Rust 99.6%
  • Shell 0.4%