Creating an ink! Project
We are going to use the ink! CLI to generate the files we need for a Substrate smart contract project.
Make sure you are in your working directory, and then run:
1
cargo contract new flipper
Copied!
This command will create a new project folder named flipper which we will explore:
1
cd flipper/
Copied!

ink! Contract Project

1
flipper
2
|
3
.
4
├── Cargo.toml
5
└── lib.rs
Copied!

Contract Source Code

The ink CLI automatically generates the source code for the "Flipper" contract, which is about the simplest "smart" contract you can build. You can take a sneak peak as to what will come by looking at the source code here:
The Flipper contract is nothing more than a bool which gets flipped from true to false through the flip() function. We won't go so deep into the details of this source code because we will be walking you through the steps to build a more advanced contract!

Testing Your Contract

You will see at the bottom of the source code there is a simple test which verifies the functionality of the contract. We can quickly test that this code is functioning as expected using the off-chain test environment that ink! provides.
In your project folder run:
1
cargo +nightly test
Copied!
To which you should see a successful test completion:
1
$ cargo +nightly test
2
running 2 tests
3
test flipper::tests::default_works ... ok
4
test flipper::tests::it_works ... ok
5
6
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Copied!
Now that we are feeling confident things are working, we can actually compile this contract to Wasm.
Last modified 2mo ago