This guide will walk you through integrating Typink into your dapp. Typink is designed to be flexible, making it easy to integrate whether you're building a new project or migrating an existing oneβespecially if your dapp already relies on external wallet connectors like SubConnect or Talisman Connect.
TypinkProvider is the main provider component that wraps your application and provides access to Typink's hooks and functionality.
Basic Setup
Wrap your application with TypinkProvider in your main entry point (e.g., main.tsx or index.tsx):
importReactDOMfrom'react-dom/client';importAppfrom'./App';import{TypinkProvider,popTestnet,alephZeroTestnet}from'typink';import{deployments}from'./contracts/deployments';// Your contract deploymentsconstSUPPORTED_NETWORKS= [popTestnet,alephZeroTestnet];functionRoot(){return (<TypinkProviderappName="My DApp"deployments={deployments}supportedNetworks={SUPPORTED_NETWORKS}defaultNetworkId={popTestnet.id}cacheMetadata={true}><App/></TypinkProvider> );}constroot=ReactDOM.createRoot(document.getElementById('root')!);root.render(<Root/>);
Key Props
appName: The name of your dApp (used when connecting to wallets)
deployments: Array of your contract deployments.
supportedNetworks: Array of networks your dApp supports
defaultNetworkId: The default network to connect to, or defaultNetworkIdsif you want to connect to multiple networks at once
cacheMetadata: Whether to cache network metadata (recommended: true)
For a complete list of props and advanced configuration (multi-network, light client, etc.), see the TypinkProvider documentation.
Setup Wallet Connector
Typink offers flexibility in wallet integration with two main approaches:
Option 1: Built-in Typink Wallet Connector (Recommended for New Projects)
The built-in wallet connector manages wallet connections, signers, and accounts internally. It supports SubWallet, Talisman, and PolkadotJS by default.
Adding Custom Wallets
You can also add custom wallet extensions:
Using the useTypink Hook
Once you've set up the built-in wallet connector, use the useTypink hook to access wallet state and actions in your components.
Available Properties:
Example: Connect Wallet Button
Example: Account Selection & Disconnect
Key Points:
Call connectWallet(id) with a wallet's id property to connect
accounts includes all accounts from all connected wallets
Use setConnectedAccount() to switch between accounts
Call disconnect() without arguments to disconnect all wallets, or pass a walletId to disconnect a specific wallet
connectedAccount and signer are automatically managed and available for contract interactions