For the complete documentation index, see llms.txt. This page is also available as Markdown.

Build an ERC20 dapp with Typink and ink! v6

In this tutorial, we'll guide you through building a complete ERC20 token dapp using Typink with ink! v6 on PolkaVM (pallet-revive). You'll learn how to create, deploy, and interact with an ERC20 token contract, including transfers and real-time event notifications.

What We'll Build:

  • ERC20 token contract using ink! v6

  • Token transfer interface with real-time balance updates

  • Transaction notifications with txToaster

  • Live Transfer event monitoring with toast notifications

Technologies:

  • Typink - React hooks for contract interactions

  • ink! v6 - Latest ink! on PolkaVM (pallet-revive)

  • POP CLI - Contract development tool

  • Next.js 15 - Frontend framework

Prerequisites

  • Node.js v20 or higher

  • pnpm (or npm/yarn/bun)

  • Rust and cargo-contract (for contract compilation)

Step 1: Create New Typink Project

Let's start by creating a new project using the Typink CLI:

Follow the interactive prompts:

  1. Project name: erc20-dapp

  2. Contract type: Select Ink! v6 (PolkaVM, pallet-revive)

  3. Networks: Select Passet Hub

The CLI will:

  • Create the project structure

  • Install dependencies

  • Setup TypinkProvider with Passet Hub

  • Initialize git repository

Navigate to your project:

Step 2: Create ERC20 Contract with POP CLI

We'll use POP CLI to create our ERC20 contract. First, install POP CLI if you haven't:

Create a new contract using POP CLI:

When prompted:

  • Template type: ERC

  • Select contract: erc20

  • Project name: erc20

This creates an erc20 folder with the ERC20 contract template.

Step 3: Compile the Contract

Navigate to the contract directory and build it:

After successful compilation, you'll find the artifacts in target/ink/:

  • erc20.contract - Bundle file (metadata + wasm)

  • erc20.json - Contract metadata

  • erc20.wasm - Contract bytecode

Copy these files to your project's contracts folder:

Step 4: Get Testnet Tokens

Before deploying, you'll need PAS testnet tokens on Passet Hub:

  1. Get PAS on Passet Hub:

Step 5: Deploy Contract via ui.use.ink

Now let's deploy the ERC20 contract:

  1. Connect Your Wallet:

    • Click "Connect Wallet"

    • Select SubWallet, Talisman, or PolkadotJS

  2. Select Network:

    • Choose "Paseo Asset Hub" from the network dropdown

  3. Upload Contract:

    • Click "Add New Contract"

    • Select "Upload New Contract Code"

    • Upload erc20.contract file

  4. Deploy Contract:

    • Constructor: new

    • total_supply: Enter 1000000000000000000000000 (1M tokens with 18 decimals)

    • Click "Deploy"

    • Sign the transaction

  5. Save Contract Address:

    • After successful deployment, copy the contract address

    • Example: 0x1234...5678

Step 6: Register Contract Deployment

Update src/contracts/deployments.ts to register your ERC20 contract:

Step 7: Generate TypeScript Bindings

The project includes a pre-configured typegen script. Run it to generate type-safe bindings:

This generates TypeScript types in src/contracts/types/erc20/ including the Erc20ContractApi interface.

Step 8: Display Token Information

Create a new component src/components/erc20-board.tsx:

Update src/app/page.tsx to use the new component:

Start the development server:

Visit http://localhost:3000 and connect your wallet to see your token balance!

Step 9: Create Transfer Form

Now let's add a transfer form. Update src/components/erc20-board.tsx:

The form will look like below:

Step 10: Watch Transfer Events

Let's add real-time Transfer event monitoring with toast notifications. Update src/components/erc20-board.tsx:

The notification appears when the contract emits a Transfer event.

Final Result

Congratulations! You've built a complete ERC20 token dapp with:

  • βœ… Real-time Balance Display - Auto-updates on new blocks

  • βœ… Token Transfer Form - Send tokens to any address

  • βœ… Transaction Notifications - Real-time progress with txToaster

  • βœ… Event Monitoring - Live Transfer event notifications

  • βœ… Type-Safe Interactions - Full TypeScript support

Features Demonstrated

Contract Queries:

  • useContractQuery with watch: true for real-time updates

  • Auto-refresh balance after transactions

Contract Transactions:

  • useContractTx for sending transfers

  • txToaster for transaction progress tracking

  • Error handling and validation

Event Watching:

  • useWatchContractEvent for Transfer events

  • Filtered notifications for user-relevant events

  • Real-time balance refresh on events

Resources


Happy Building! πŸŽ‰

Last updated