DEV Community

Cover image for Getting Started with Smart Contracts on Polkadot: A Guide to Ink
Fred
Fred

Posted on

Getting Started with Smart Contracts on Polkadot: A Guide to Ink

Introduction

In this tutorial, we’ll walk through deploying a smart contract written in ink! (Rust-based smart contract language) using the use.ink UI playground. We’ll also set up and connect our wallet using the Polkadot.js extension to sign transactions and deploy the contract to a test network.
You can check out my article on deploying smart contracts locally here.

Prerequisites

Before we start, make sure you have:

  1. Rust installed since we will compile locally.
  2. A modern browser (I’ll be using Firefox).
  3. The Polkadot.js extension installed.
  4. Some test tokens (usually on a testnet) Claim here.

Setting Up Polkadot.js Extension

  1. Install the extension Download it from Mozilla Add-ons or Chrome Web Store.
  2. Create a wallet
    Image of polkadot.js extension

    • Open the extension.
    • Click “+” to create a new account.
    • Save your seed phrase securely (very important!).
    • Give your account a recognizable name.
  3. Get test tokens
    Depending on which network you're deploying to (e.g., PassetHub), you might need some test tokens. You can request them from a faucet.
    Image of the faucet webpage

  4. Verify connection
    Visit Polkadot.js Apps to make sure your account shows up.

Image of the polkadot developer portal

Writing or Uploading Your Contract on use.ink

  1. Visit use.ink playground:

  2. Upload your compiled .contract file
    Image of uploading contract

  3. You can interact with your smart contract after following through the steps and instantiating.
    Final results:
    Image of deployed smart contract

Troubleshooting

1. AccountUnmapped

Example error:

AccountUnmapped
An `AccountID32` account tried to interact with the pallet without having a mapping.Call [`Pallet::map_account`] in order to create a mapping for the account.
Enter fullscreen mode Exit fullscreen mode

Mapping simply means linking your wallet account to the on-chain account system so it can interact with smart contracts and pallets properly. It does not create a new address — it just registers it on-chain.

Image of AccountUnmapped error

Solution

  • Visit the polkadot developer page here.
  • Change the network on the far left!

Image of polkadot site

  • Change to test paseo and choose PassetHub- contracts : via IBP1.
    Image of changing network on polkadot developer site

  • Go to Developer section, then Intrinsics. - In the submit the following extrinsic field, select revive and mapAccount() as appropriate and submit.
    Image of polkadot site with changes

2. Polkadot extension doesn't connect on the Polkadot site or use.ink site

The wallet extension is not connecting by default, no worries!

Solution

  • Access the polkadot extension.
  • Click on Connect Accounts and confirm in the popup.
  • Refresh the page.

Image of the polkadot.js wallet

Conclusion

Deploying ink! smart contracts using use.ink and Polkadot.js is now easier than ever. By following these steps, you can quickly upload, deploy, and interact with your contracts on a test network.

Always remember to use test tokens first, and verify your wallet connection to avoid common errors like AccountUnmapped.

Top comments (3)

Collapse
 
christine_kerubo_fdb54bd5 profile image
Christine Kerubo

Nice work 👍

Collapse
 
fredgitonga profile image
Fred

thank you Christine! hoping the guide was helpful and you were able to deploy your smart contract

Collapse
 
christine_kerubo_fdb54bd5 profile image
Christine Kerubo

The guide was soo helpful. I am in the process of deploying my smartcontract