Flipper Contract
This is step-by-step explanation of the process behind building an ink! smart contract, using a simple app called Flipper. The examples provided within this guide will help you develop an understanding of the basic elements and structure of ink! smart contracts.
What is Flipper?
Flipper is a basic smart contract that allows the user to toggle a boolean value located in storage to either true
or false
. When the flip function is called, the value will change from one to the other.
Prerequisites
Please refer to the previous section for the list of prerequisites.
Flipper Smart Contract
In a new project folder, execute the following:
$ cargo contract new flipper # flipper is introduced from the beginning.
$ cd flipper/
$ cargo contract build #build flipper app
💡 If you receive an error such as:
ERROR: cargo-contract cannot build using the "stable" channel. Switch to nightly.
Execute:
$ rustup default nightly
to reconfigure the default Rust toolchain to use the nightly build, or
$ cargo +nightly contract build
to use the nightly build explicitly, which may be appropriate for developers working exclusively with ink!
Once the operation has finished, and the Flipper project environment has been initialized, we can perform an examination of the file and folder structure. Let’s dive a bit deeper into the project structure: