34 releases (8 stable)

Uses new Rust 2021

new 2.0.0-alpha.4 Oct 3, 2022
2.0.0-alpha.1 Aug 25, 2022
1.5.0 Aug 15, 2022
1.4.0 May 20, 2022
0.1.1 Apr 24, 2019

#7 in Magic Beans

Download history 165/week @ 2022-06-14 128/week @ 2022-06-21 138/week @ 2022-06-28 201/week @ 2022-07-05 212/week @ 2022-07-12 152/week @ 2022-07-19 231/week @ 2022-07-26 190/week @ 2022-08-02 118/week @ 2022-08-09 134/week @ 2022-08-16 168/week @ 2022-08-23 218/week @ 2022-08-30 181/week @ 2022-09-06 191/week @ 2022-09-13 132/week @ 2022-09-20 128/week @ 2022-09-27

660 downloads per month

GPL-3.0 license

400KB
9K SLoC

cargo-contract

CI Status Latest Release stack-exchange

squink, the ink! mascotcargo-contract is a CLI tool which helps you develop smart contracts in Parity's ink!.
ink! is a Rust eDSL which allows you to write smart contracts for blockchains built on the Substrate framework.


Guided Tutorial for Beginners  •   ink! Documentation Portal


More relevant links:

  • Find answers to your questions by joining our Stack Exchange community
  • ink! ‒ The main ink! repository with smart contract examples
  • Contracts UI ‒ Frontend for contract deployment and interaction
  • Substrate Contracts Node ‒ Simple Substrate blockchain which includes smart contract functionality

Installation

  • Step 1: rustup component add rust-src.

  • Step 2: Install binaryen in a version >= 99:

    There's only an old version in your distributions package manager? Just use a binary release.

  • Step 3: Install dylint

    • (MacOS) brew install openssl
    • cargo install cargo-dylint dylint-link.
  • Step 4: cargo install --force --locked cargo-contract.

You can always update the cargo-contract binary to the latest version by running the Step 4.

Installation using Docker Image

If you prefer to use Docker instead we have a Docker image available on the Docker Hub:

# Pull the latest stable image.
docker pull paritytech/contracts-ci-linux:production

# Create a new contract in your current directory.
docker run --rm -it -v $(pwd):/sources paritytech/contracts-ci-linux:production \
  cargo +nightly contract new --target-dir /sources my_contract

# Build the contract. This will create the contract file under
# `my_contract/target/ink/my_contract.contract`.
docker run --rm -it -v $(pwd):/sources paritytech/contracts-ci-linux:production \
  cargo +nightly contract build --manifest-path=/sources/my_contract/Cargo.toml

If you want to reproduce other steps of CI process you can use the following guide.

Usage

You can always use cargo contract help to print information on available commands and their usage.

For each command there is also a --help flag with info on additional parameters, e.g. cargo contract new --help.

cargo contract new my_contract

Creates an initial smart contract with some scaffolding code into a new folder my_contract .

The contract contains the source code for the Flipper contract, which is about the simplest "smart" contract you can build ‒ a bool which gets flipped from true to false through the flip() function.

cargo +nightly contract build

Compiles the contract into optimized WebAssembly bytecode, generates metadata for it, and bundles both together in a <name>.contract file, which you can use for deploying the contract on-chain.

cargo contract build must be run using the nightly toolchain. If you have rustup installed, the simplest way to do so is cargo +nightly contract build.

To avoid having to always add +nightly you can also set nightly as the default toolchain of a directory by executing rustup override set nightly in it.

cargo contract check

Checks that the code builds as WebAssembly. This command does not output any <name>.contract artifact to the target/ directory.

cargo contract test

Runs test suites defined for a smart contract off-chain.

cargo contract upload

Upload a contract to a pallet-contracts enabled chain. See extrinsics.

cargo contract instantiate

Create an instance of a contract on chain. See extrinsics.

cargo contract call

Invoke a message on an existing contract on chain. See extrinsics.

cargo contract decode

Decodes a contracts input or output data.

This can be either an event, an invocation of a contract message, or an invocation of a contract constructor.

The argument has to be given as hex-encoding, starting with 0x.

License

The entire code within this repository is licensed under the GPLv3.

Please contact us if you have questions about the licensing of our products.

Dependencies

~26–35MB
~735K SLoC