Polkadot's ink! for writing smart contracts
[![linux][a1]][a2] [![codecov][c1]][c2] [![coveralls][d1]][d2] [![loc][e1]][e2] [![stack-exchange][s1]][s2]
[a1]: https://github.com/use-ink/ink/workflows/continuous-integration/badge.svg
[a2]: https://github.com/use-ink/ink/actions?query=workflow%3Acontinuous-integration+branch%3Amaster
[c1]: https://codecov.io/gh/use-ink/ink/branch/master/graph/badge.svg
[c2]: https://codecov.io/gh/use-ink/ink/branch/master
[d1]: https://coveralls.io/repos/github/use-ink/ink/badge.svg?branch=master
[d2]: https://coveralls.io/github/use-ink/ink?branch=master
[e1]: https://tokei.rs/b1/github/use-ink/ink?category=code
[e2]: https://github.com/Aaronepower/tokei#badges
[f1]: https://img.shields.io/badge/click-blue.svg
[f2]: https://use-ink.github.io/ink/ink_storage
[g1]: https://img.shields.io/badge/click-blue.svg
[g2]: https://use-ink.github.io/ink/ink_env
[i1]: https://img.shields.io/badge/click-blue.svg
[i2]: https://use-ink.github.io/ink/ink_prelude
[j1]: https://img.shields.io/badge/click-blue.svg
[j2]: https://use-ink.github.io/ink/ink
[k1]: https://img.shields.io/badge/matrix-chat-brightgreen.svg?style=flat
[k2]: https://app.element.io/#/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/smart-contracts/) •
[ink! Documentation Portal](https://use.ink) •
[Developer Documentation](https://use-ink.github.io/ink/ink)
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/use-ink/cargo-contract) ‒ CLI tool for ink! contracts
* [Contracts UI](https://contracts-ui.substrate.io/) ‒ Frontend for contract instantiation and interaction
* [Substrate Contracts Node](https://github.com/paritytech/substrate-contracts-node) ‒ Simple Substrate blockchain which includes smart contract functionality
* [Awesome ink!](https://github.com/use-ink/awesome-ink) - A curated list of awesome projects for Polkadot's ink!
* We post announcements on [Matrix][k2] and [Discord][l2] (in the
[`ink_smart-contracts`](https://discord.com/channels/722223075629727774/765280480609828864) channel).
## Table of Contents
- [Table of Contents](#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)
- [Normal Design](#normal-design)
- [Flat Design](#flat-design)
- [Contributing](#contributing)
- [License](#license)
## Play with It
The best way to start is to check out the [Getting Started](https://use.ink/getting-started/setup)
page in our documentation.
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 named "Contracts" on Rococo. Rococo is a Substrate based
parachain which supports ink! smart contracts. For further instructions on using this
testnet, follow the instructions in
[our documentation](https://use.ink/testnet).
The [Contracts UI](https://contracts-ui.substrate.io/) 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/use-ink/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 contract build
```
As a result you'll get a `target/flipper.wasm` file, a `flipper.json` file and a `