Your first ink! smart contract
Learn how to create and deploy your first ink! smart contract
Last updated
Learn how to create and deploy your first ink! smart contract
Last updated
Developers who want to learn how to:
On completion of this tutorial, developers will be able to:
create, build, test, and deploy ink! smart contracts
interact with the deployed contract
Let's install the powerful Pop CLI tool which will be used throughout this tutorial.
Make sure the Pop CLI tool has been installed correctly by running the pop
command in your terminal.
TL;DR;
Questions:
What are ink! smart contracts?
What are the benefits of using the ink! programming language?
Why use ink! to develop smart contracts?
What makes ink! so nice?
Take 10 minutes to skim over the ink! documentation and answer the above questions.
ink! allows you to write smart contracts using Rust. That means you get all the benefits of the Rust programming language.
The ink! embedded domain-specific language (eDSL) retro-fits your Rust code with powerful features that enhance smart contract development. In doing so, ink! improves the developer ergonomics when it comes to using Rust for writing smart contracts.
Let's create a simple ink! smart contract using the "flipper" template:
Flipper is a good starting point for those new to ink! smart contract development.
Let's look at our first bit of ink! code.
You will see the following in this directory:
Inside lib.rs
you will find all the contract logic.
Take a moment to get familiar with the ink! programming language:
Let's build flipper! Make sure you are inside the flipper directory and run the following command:
Awesome, your contract is built!
With Pop CLI, you can also run your smart contract tests.
Okay, so you contract builds and passes the tests. We can now deploy the contract to Pop.
Once you have battle-tested your smart contract using unit and e2e tests, you are ready to test your smart contract on the Pop Testnet.
Before you deploy, make sure you have bridged some tokens from the Polkadot Relay chain to your Pop account. To learn how to do this, go here:
Now that your account is funded on Pop, you can deploy your contract.
Go to: contracts.onpop.io
Select "Add New Contract"
Select "Upload New Contract Code"
Next, give the contract a name and upload the flipper/target/ink/flipper.contract
file which contains the contract's Wasm code as well as the contract's metadata.
You can now interact with your contract!
Congrats! Your contract is deployed!
Technical Support
Create a question and tag it with "pop
"
Share the StackExchange question in our Pop Support Telegram channel
Take a minute to give us feedback on this tutorial so we can improve it!