Docs
Submit an issue
Smart Contracts
Smart Contracts
  • WELCOME
    • Smart Contracts
    • Installing Pop CLI
    • How to contribute
  • GUIDES
    • Get tokens on Pop (Testnet)
    • Set up your development environment
    • Create a new contract
    • Build your contract
    • Run your unit tests
    • Deploy your contract locally
      • Deploy locally on a Solochain
      • Deploy locally on Pop
    • Call your contract
    • Running E2E tests
    • Deploy on Pop
    • Securely Sign Transactions from CLI
    • Getting Started with ink! v6
  • TUTORIALS
    • Your first ink! smart contract
    • Mint a PSP22 token on Pop
  • POP CLI
    • welcome
    • install
    • new
    • build
    • call
    • up
    • test
    • clean
Powered by GitBook
On this page
  • Audience
  • Learning Objectives
  • Installing Pop CLI
  • Getting Started
  • Building the ink! smart contract
  • Run your ink! smart contract unit tests
  • Deploy your contract
  • Feedback

Was this helpful?

Edit on GitHub
  1. TUTORIALS

Your first ink! smart contract

Learn how to create and deploy your first ink! smart contract

PreviousGetting Started with ink! v6NextMint a PSP22 token on Pop

Last updated 7 months ago

Was this helpful?

Audience

Developers who want to learn how to:

  • use the Pop CLI tool to speed up development

  • deploy smart contracts on Pop

Learning Objectives

On completion of this tutorial, developers will be able to:

  • create, build, test, and deploy ink! smart contracts

  • deploy smart contracts to Pop on Paseo (Polkadot's Test Network)

  • interact with the deployed contract

Installing Pop CLI

Let's install the powerful Pop CLI tool which will be used throughout this tutorial.

cargo install --force --locked pop-cli

Make sure the Pop CLI tool has been installed correctly by running the pop command in your terminal.

pop --help

Getting Started

TL;DR;

  • Why ink!? talk by @brunopgalvao

Questions:

  1. What are ink! smart contracts?

  2. What are the benefits of using the ink! programming language?

  3. Why use ink! to develop smart contracts?

  4. What makes ink! so nice?

Take 10 minutes to skim over the ink! documentation and answer the above questions.

ink! contracts are smart(er)

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:

pop new contract
┌   Pop CLI : Generate a contract
│
â—‡  Select a template type: 
│  Examples 
│
â—‡  Select the contract:
│  Standard 
│
â—†  Where should your project be created?
│  ./flipper 
â””  

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:

flipper
  └─ lib.rs
  └─ Cargo.toml
  └─ .gitignore

Inside lib.rs you will find all the contract logic.

Take a moment to get familiar with the ink! programming language:

Building the ink! smart contract

Let's build flipper! Make sure you are inside the flipper directory and run the following command:

pop build

┌   Pop CLI : Building a contract
│
 [==] Checking clippy linting rules
   Compiling proc-macro2 v1.0.79
   Compiling unicode-ident v1.0.12
   Compiling syn v1.0.109
   Compiling equivalent v1.0.1
   Compiling hashbrown v0.14.3
   Compiling winnow v0.5.40
   ....
   Finished release [optimized] target(s) in 21.17s
   Running `target/ink/release/metadata-gen`
 [==] Generating bundle
â—†  
│  Original wasm size: 21.3K, Optimized: 1.6K
│  
│  The contract was built in RELEASE mode.
│  
│  Your contract artifacts are ready. You can find them in:
│  /Users/bruno/src/flipper/target/ink
│  
│    - flipper.contract (code + metadata)
│    - flipper.wasm (the contract's code)
│    - flipper.json (the contract's metadata)
│  
â””  Build completed successfully!

Awesome, your contract is built!

With Pop CLI, you can also run your smart contract tests.

Run your ink! smart contract unit tests

pop test contract

┌   Pop CLI : Building a contract
│
 [==] Checking clippy linting rules
   Compiling proc-macro2 v1.0.79
   ....
   Compiling flipper v0.1.0 (/Users/bruno/src/pop-cli/flipper)
    Finished test [unoptimized + debuginfo] target(s) in 8.06s
     Running unittests lib.rs (target/debug/deps/flipper-ff1505839f6873de)

running 2 tests
test flipper::tests::it_works ... ok
test flipper::tests::default_works ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

   Doc-tests flipper

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

â””  Unit testing complete

Okay, so you contract builds and passes the tests. We can now deploy the contract to Pop.

Deploy your contract

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:

  • https://learn.onpop.io/contracts/guides/get-tokens-on-pop

Deploy

Now that your account is funded on Pop, you can deploy your contract.

  1. Go to: contracts.onpop.io

  2. Select "Add New Contract"

  3. 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!

Resources

  • https://use.ink

Technical Support

  • Polkadot Stack Exchange

    • Create a question and tag it with "pop"

    • Share the StackExchange question in our Pop Support Telegram channel

Feedback

Take a minute to give us feedback on this tutorial so we can improve it!