interchain-token-sdk
v2.0.3
Published
SDK for deploying and managing interchain tokens across multiple chains using Axelar network
Maintainers
Readme
Interchain Tokens SDK
A TypeScript SDK for deploying new tokens across multiple chains using the Axelar network. This SDK allows you to deploy a new token on one chain and automatically deploy its corresponding versions on other supported chains.
Currently Supported Networks (Testnet Only)
- Base Sepolia
- Optimism Sepolia
- Arbitrum Sepolia
Installation
npm install interchain-tokens-sdkUsage
Basic Setup
import {
deployInterchainTokenMulticall,
registerAndDeployCanonicalInterchainTokenMulticall,
estimateRemoteDeploymentGas,
SUPPORTED_CHAINS,
isValidERC20Token
} from "interchain-tokens-sdk";
import { createWalletClient, createPublicClient, http } from "viem";
import { baseSepolia } from "viem/chains";
// Create wallet and public clients for your source chain (e.g., Base Sepolia)
const walletClient = createWalletClient({
account,
chain: baseSepolia,
transport: http(RPC_URL)
});
const publicClient = createPublicClient({
chain: baseSepolia,
transport: http(RPC_URL)
});Deploying a New Token
// Deploy your token across chains
const result = await deployInterchainTokenMulticall(
tokenName, // string: your token name
tokenSymbol, // string: your token symbol
decimals, // number: number of decimals (e.g., 18)
initialSupply, // number: initial token supply
minterAddress, // string: address that can mint tokens
destinationChains, // string[]: array of supported chain names
walletClient,
publicClient
);Registering an Existing Token
// Register and deploy an existing ERC20 token across chains
const result = await registerAndDeployCanonicalInterchainTokenMulticall(
tokenAddress, // string: address of your existing ERC20 token
destinationChains, // string[]: array of supported chain names
walletClient,
publicClient
);Estimating Gas for Remote Deployment
There are two ways to estimate gas for remote deployments:
- For New Tokens:
// Estimate gas required for deploying a new token
const gasEstimate = await estimateNewTokenDeploymentGas(
sourceChainName, // string: name of the source chain (e.g., "base-sepolia")
destinationChain, // string: name of the destination chain
tokenName, // string: name of the token
tokenSymbol, // string: symbol of the token
decimals, // number: number of decimals
initialSupply, // number: initial token supply
minterAddress // string: address that can mint tokens
);- For Existing Tokens:
// Estimate gas required for deploying an existing token
const gasEstimate = await estimateExistingTokenDeploymentGas(
sourceChainName, // string: name of the source chain (e.g., "base-sepolia")
destinationChain, // string: name of the destination chain
tokenAddress // string: address of the existing token
);Gas Estimation Results
Both gas estimation functions return a bigint representing the estimated gas in wei. The estimation includes:
- Base gas cost for the operation
- 20% buffer for safety
- Cross-chain messaging fees
- If estimation fails, a default value of 600,000 gas units is returned
Validating ERC20 Tokens
// Check if an address is a valid ERC20 token
const isValid = await isValidERC20Token(
tokenAddress, // string: address to validate
publicClient // PublicClient: viem public client
);API Reference
Deployment Result
interface DeploymentResult {
hash: `0x${string}`; // transaction hash
tokenDeployed?: {
tokenId: `0x${string}`; // unique identifier across chains
tokenAddress: `0x${string}`; // token contract address
minter: `0x${string}`; // minter address
name: string; // token name
symbol: string; // token symbol
decimals: number; // token decimals
salt: `0x${string}`; // deployment salt
};
}Gas Estimation Result
// Returns a bigint representing the estimated gas in wei
const gasEstimate: bigint = await estimateRemoteDeploymentGas(...);Important Notes
Token Types:
- New Tokens: Use
deployInterchainTokenMulticallto deploy a new token across chains - Existing Tokens: Use
registerAndDeployCanonicalInterchainTokenMulticallto register and deploy an existing ERC20 token
- New Tokens: Use
Source Chain: You can deploy from any of the supported chains, but make sure your wallet has enough native tokens for:
- The deployment transaction
- Gas fees for cross-chain messaging (use
estimateRemoteDeploymentGasto estimate)
Destination Chains: When specifying destination chains, use the chain identifiers exactly as follows:
- "base-sepolia"
- "optimism-sepolia"
- "arbitrum-sepolia"
Gas Estimation:
- Always estimate gas before deployment using
estimateRemoteDeploymentGas - The estimation includes a 20% buffer for safety
- If estimation fails, a default value of 600,000 gas units is returned
- Always estimate gas before deployment using
Token Validation:
- Use
isValidERC20Tokento validate token addresses before deployment - This helps prevent deployment of invalid tokens
- Use
Axelar Network: This SDK uses Axelar's infrastructure for cross-chain communication. The deployment process:
- Deploys the token on the source chain
- Creates token managers on destination chains
- Sets up the cross-chain token mapping
Development
To contribute or modify the SDK:
- Clone the repository
- Install dependencies:
npm install - Build:
npm run build - Test:
npm test
License
MIT
