Start a new dapp

Getting Started with Typink

Typink is a React hooks library for building dApps that interact with ink! and Solidity smart contracts on Polkadot blockchains. With Typink, you get a unified developer experience - the same hooks and APIs work seamlessly across ink! v5 (WASM), ink! v6 (PolkaVM), and Solidity contracts.

Create a New Project

Start by creating a new Typink project using the interactive CLI:

pnpm create typink@latest

The CLI will guide you through an interactive setup:

1. Enter Project Name

? Project name: my-typink-dapp

2. Select Contract Type

Choose the type of contracts you'll be working with:

? Select contract type:
❯ Ink! v6 (PolkaVM, pallet-revive)
  Ink! v6 using Sol ABI (PolkaVM, pallet-revive)
  Solidity (PolkaVM, pallet-revive)
  Ink! v5 (WASM, pallet-contracts)

Contract Types:

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

  • Ink! v6 Sol ABI - ink! v6 with Solidity-style ABI

  • Solidity - Solidity smart contracts on PolkaVM

  • Ink! v5 - Legacy ink! on WASM (pallet-contracts)

3. Select Networks

Choose one or more networks for your dApp:

Available networks depend on your contract type:

  • pallet-contracts (Ink! v5): Pop Testnet, Aleph Zero Testnet, Aleph Zero, Astar

  • pallet-revive (Ink! v6/Solidity): Pop Testnet, Passet Hub

Start Development

Navigate to your project and start the development server:

Open http://localhost:3000 to see your dApp running!

Project Structure

Your project follows Next.js 15 App Router structure:

Key Files

src/providers/app-provider.tsx - Configures TypinkProvider with networks, wallets, and contracts:

src/contracts/deployments.ts - Registers contract deployments:

Explore the Example

Your project includes a pre-deployed example contract with working interactions:

  1. Connect Wallet - Click "Connect Wallet" and select SubWallet, Talisman, or PolkadotJS

  2. View State - See the current contract state (e.g., Flipper value, Storage value)

  3. Send Transactions - Interact with the contract (e.g., flip the boolean, set storage)

  4. Watch Progress - Transaction toasts show real-time progress

Example Contracts

  • Ink! v5: Greeter contract (set and get messages)

  • Ink! v6: Flipper contract (flip boolean value)

  • Ink! v6 Sol ABI: Flipper contract with Solidity-style ABI

  • Solidity: Storage contract (set and get uint256 value)

Add Your Own Contracts

1. Deploy Your Contract

Deploy your contract to a supported network using:

You'll receive a contract address after successful deployment.

2. Generate TypeScript Bindings

The project includes a pre-configured typegen script (./scripts/typegen.ts) that generates type-safe bindings for all contracts in src/contracts/artifacts/.

First, place your contract metadata/ABI files in src/contracts/artifacts/, then run:

This script automatically processes all metadata/ABI files in src/contracts/artifacts/ and generates TypeScript bindings to src/contracts/types/. The generated TypeScript API (e.g., MyContractApi) will be available in src/contracts/types/my_contract/.

3. Register Contract Deployment

Add your contract to src/contracts/deployments.ts:

Unified Hooks - Works with All Contract Types

Typink's hooks provide a unified API that works identically across ink! v5, ink! v6, and Solidity contracts.

useContract - Initialize Contract Instance

Get a typed contract instance:

useContractQuery - Query Contract State

Read contract state with automatic type inference:

Ink! v6 Flipper Example:

Solidity Storage Example:

πŸ’‘ The hooks are identical! Only the contract type and method names change.

useContractTx - Send Transactions

Execute contract transactions with the same API:

Ink! v6 Flipper Example:

Solidity Storage Example:

πŸ’‘ Identical hook usage! The only difference is the contract type and arguments.

useWatchContractEvent - Listen to Events

Watch for contract events with type-safe event data:

Ink! v6 Example:

πŸ’‘ Works the same for Solidity contracts! Just use your Solidity contract's event names.

useDeployerTx - Deploy New Contracts

Deploy new contract instances:

Setup Transaction Toaster

Before using txToaster(), configure the global adapter in your app provider:

Supported toast libraries:

  • Sonner (recommended) - SonnerAdapter

  • React-Toastify - ReactToastifyAdapter

  • React-Hot-Toast - ReactHotToastAdapter

See the txToaster documentation for more details.

Complete Example

Here's a complete component showing query, transaction, and events:

πŸ’‘ This exact same pattern works for Solidity contracts! Just change the contract type and method names.


Happy building with Typink! πŸŽ‰

Last updated

Was this helpful?