Parity's ink! for writing smart contracts
[![linux][a1]][a2] [![codecov][c1]][c2] [![coveralls][d1]][d2] [![loc][e1]][e2] [![stack-exchange][s1]][s2]
[a1]: https://gitlab.parity.io/parity/ink/badges/master/pipeline.svg
[a2]: https://gitlab.parity.io/parity/ink/pipelines?ref=master
[c1]: https://codecov.io/gh/paritytech/ink/branch/master/graph/badge.svg
[c2]: https://codecov.io/gh/paritytech/ink/branch/master
[d1]: https://coveralls.io/repos/github/paritytech/ink/badge.svg?branch=master
[d2]: https://coveralls.io/github/paritytech/ink?branch=master
[e1]: https://tokei.rs/b1/github/paritytech/ink?category=code
[e2]: https://github.com/Aaronepower/tokei#badges
[f1]: https://img.shields.io/badge/click-blue.svg
[f2]: https://paritytech.github.io/ink/ink_storage
[g1]: https://img.shields.io/badge/click-blue.svg
[g2]: https://paritytech.github.io/ink/ink_env
[i1]: https://img.shields.io/badge/click-blue.svg
[i2]: https://paritytech.github.io/ink/ink_prelude
[j1]: https://img.shields.io/badge/click-blue.svg
[j2]: https://paritytech.github.io/ink/ink_lang
[k1]: https://img.shields.io/badge/matrix-chat-brightgreen.svg?style=flat
[k2]: https://riot.im/app/#/room/#ink:matrix.parity.io
[l1]: https://img.shields.io/discord/722223075629727774?style=flat-square&label=discord
[l2]: https://discord.com/invite/wGUDt2p
[s1]: https://img.shields.io/badge/click-white.svg?logo=StackExchange&label=ink!%20Support%20on%20StackExchange&labelColor=white&color=blue
[s2]: https://substrate.stackexchange.com/questions/tagged/ink?tab=Votes
>
ink! is an [eDSL](https://wiki.haskell.org/Embedded_domain_specific_language) to write smart contracts in Rust for blockchains built on the [Substrate](https://github.com/paritytech/substrate) framework. ink! contracts are compiled to WebAssembly.
[Guided Tutorial for Beginners](https://docs.substrate.io/tutorials/v3/ink-workshop/pt1) •
[ink! Documentation Portal](https://ink.substrate.io) •
[Developer Documentation](https://paritytech.github.io/ink/ink_lang/)
More relevant links:
* [Substrate Stack Exchange](https://substrate.stackexchange.com/questions/tagged/ink?tab=Votes) ‒ Forum for getting your ink! questions answered
* [`cargo-contract`](https://github.com/paritytech/cargo-contract) ‒ CLI tool for ink! contracts
* [Contracts UI](https://paritytech.github.io/contracts-ui/) ‒ Frontend for contract instantiation and interaction
* [Substrate Contracts Node](https://github.com/paritytech/substrate-contracts-node) ‒ Simple Substrate blockchain which includes smart contract functionality
* We post announcements on [Matrix][k2] and [Discord][l2] (in the
[`ink_smart-contracts`](https://discord.com/channels/722223075629727774/765280480609828864) channel).
## Table of Contents
* [Play with It](#play-with-it)
* [Usage](#usage)
* [Hello, World! ‒ The Flipper](#hello-world--the-flipper)
* [Examples](#examples)
* [How it Works](#how-it-works)
* [ink! Macros & Attributes Overview](#ink-macros--attributes-overview)
* [Entry Point](#entry-point)
* [Trait Definitions](#trait-definitions)
* [Off-chain Testing](#off-chain-testing)
* [Developer Documentation](#developer-documentation)
* [Community Badges](#community-badges)
* [Contributing](#contributing)
* [License](#license)
## Play with It
If you want to have a local setup you can use our [`substrate-contracts-node`](https://github.com/paritytech/substrate-contracts-node) for a quickstart.
It's a simple Substrate blockchain which includes the Substrate module for smart contract functionality ‒ the `contracts` pallet (see [How it Works](#how-it-works) for more).
We also have a live testnet on [Rococo](https://github.com/paritytech/cumulus/#rococo-)
called [Canvas](https://ink.substrate.io/canvas). Canvas is a Substrate based
parachain which supports ink! smart contracts. For further instructions on using this
testnet, follow the instructions in the
[our documentation](https://ink.substrate.io/canvas#rococo-deployment).
For both types of chains the [Contracts UI](https://paritytech.github.io/contracts-ui/)
can be used to instantiate your contract to a chain and interact with it.
## Usage
A prerequisite for compiling smart contracts is to have Rust and Cargo installed. Here's [an installation guide](https://doc.rust-lang.org/cargo/getting-started/installation.html).
We recommend installing [`cargo-contract`](https://github.com/paritytech/cargo-contract) as well.
It's a CLI tool which helps set up and manage WebAssembly smart contracts written with ink!:
```
cargo install cargo-contract --force
```
Use the `--force` to ensure you are updated to the most recent `cargo-contract` version.
In order to initialize a new ink! project you can use:
```
cargo contract new flipper
```
This will create a folder `flipper` in your work directory.
The folder contains a scaffold `Cargo.toml` and a `lib.rs`, which both contain the necessary building blocks for using ink!.
The `lib.rs` contains our hello world contract ‒ the `Flipper`, which we explain in the next section.
In order to build the contract just execute this command in the `flipper` folder:
```
cargo +nightly contract build
```
As a result you'll get a file `target/flipper.wasm` file, a `metadata.json` file and a `