Migrate from existing dapp
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.
Installation
First, install the required packages:
npm install typink dedot
# or
yarn add typink dedot
# or
pnpm add typink dedotSetup TypinkProvider
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):
import ReactDOM from 'react-dom/client';
import App from './App';
import { TypinkProvider, popTestnet, alephZeroTestnet } from 'typink';
import { deployments } from './contracts/deployments'; // Your contract deployments
const SUPPORTED_NETWORKS = [popTestnet, alephZeroTestnet];
function Root() {
return (
<TypinkProvider
appName="My DApp"
deployments={deployments}
supportedNetworks={SUPPORTED_NETWORKS}
defaultNetworkId={popTestnet.id}
cacheMetadata={true}>
<App />
</TypinkProvider>
);
}
const root = 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 supportsdefaultNetworkId: The default network to connect to, ordefaultNetworkIdsif you want to connect to multiple networks at oncecacheMetadata: 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'sidproperty to connectaccountsincludes all accounts from all connected walletsUse
setConnectedAccount()to switch between accountsCall
disconnect()without arguments to disconnect all wallets, or pass awalletIdto disconnect a specific walletconnectedAccountandsignerare automatically managed and available for contract interactions
Option 2: External Wallet Connector (For Existing DApps)
If your dApp already uses SubConnect or Talisman Connect, you can easily integrate Typink by passing signer and connectedAccount props.
SubConnect Integration
Talisman Connect Integration
Last updated
Was this helpful?