Granite Upgrade Activates in06d:02h:04m:26s
Interchain Token Transfers

Transfer Methods

approveToken

Approves the token home contract to spend tokens on the source chain.

Parameters

ParameterTypeRequiredDescription
walletClientWalletClientYesWallet client for signing
sourceChainChainConfigYes*Source chain configuration
tokenHomeContractAddressYesToken home contract address
tokenAddressAddressYesERC20 token address
amountInBaseUnitnumberYesAmount to approve (in base units)

* Required if not set in client constructor

Returns

TypeDescription
Promise<{ txHash: 0x${string} }>Transaction hash

Example

const { txHash } = await ictt.approveToken({
  walletClient: wallet,
  sourceChain: avalancheFuji,
  tokenHomeContract: tokenHomeAddress,
  tokenAddress: tokenAddress,
  amountInBaseUnit: 1000,
});

sendToken

Sends tokens from the source chain to the destination chain.

Parameters

ParameterTypeRequiredDescription
walletClientWalletClientYesWallet client for signing
sourceChainChainConfigYes*Source chain configuration
destinationChainChainConfigYes*Destination chain configuration
tokenHomeContractAddressYesToken home contract address
tokenRemoteContractAddressYesToken remote contract address
recipientAddressYesRecipient address on destination chain
amountInBaseUnitnumberYesAmount to send (in base units)
feeTokenAddressAddressNoFee token address
feeAmountnumberNoFee amount

* Required if not set in client constructor

Returns

TypeDescription
Promise<{ txHash: 0x${string} }>Transaction hash

Example

const { txHash } = await ictt.sendToken({
  walletClient: wallet,
  sourceChain: avalancheFuji,
  destinationChain: dispatch,
  tokenHomeContract: tokenHomeAddress,
  tokenRemoteContract: tokenRemoteAddress,
  recipient: "0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6",
  amountInBaseUnit: 100,
});

Complete Workflow

import { createICTTClient } from "@avalanche-sdk/interchain";
import { avalancheFuji, dispatch } from "@avalanche-sdk/interchain/chains";

const ictt = createICTTClient(avalancheFuji, dispatch);

// 1. Deploy token
const { contractAddress: tokenAddress } = await ictt.deployERC20Token({
  walletClient: wallet,
  sourceChain: avalancheFuji,
  name: "My Token",
  symbol: "MTK",
  initialSupply: 1000000,
});

// 2. Deploy home contract
const { contractAddress: tokenHomeAddress } =
  await ictt.deployTokenHomeContract({
    walletClient: wallet,
    sourceChain: avalancheFuji,
    erc20TokenAddress: tokenAddress,
    minimumTeleporterVersion: 1,
  });

// 3. Deploy remote contract
const { contractAddress: tokenRemoteAddress } =
  await ictt.deployTokenRemoteContract({
    walletClient: wallet,
    sourceChain: avalancheFuji,
    destinationChain: dispatch,
    tokenHomeContract: tokenHomeAddress,
  });

// 4. Register remote with home
await ictt.registerRemoteWithHome({
  walletClient: wallet,
  sourceChain: avalancheFuji,
  destinationChain: dispatch,
  tokenRemoteContract: tokenRemoteAddress,
});

// 5. Approve tokens
await ictt.approveToken({
  walletClient: wallet,
  sourceChain: avalancheFuji,
  tokenHomeContract: tokenHomeAddress,
  tokenAddress: tokenAddress,
  amountInBaseUnit: 1000,
});

// 6. Send tokens
const { txHash } = await ictt.sendToken({
  walletClient: wallet,
  sourceChain: avalancheFuji,
  destinationChain: dispatch,
  tokenHomeContract: tokenHomeAddress,
  tokenRemoteContract: tokenRemoteAddress,
  recipient: "0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6",
  amountInBaseUnit: 100,
});

Is this guide helpful?