Getting Started
Getting Started with the Interchain SDK
Interchain SDK
Interchain SDK The Interchain SDK is a TypeScript SDK for interacting with the Interchain Messaging Protocol (ICM) and Teleporter on Avalanche.
Features:
- Type-safe ICM client for sending cross-chain messages
- Works seamlessly with wallet clients
- Built-in support for Avalanche C-Chain and custom subnets
- Built-in support for Avalanche C-Chain and custom subnets
The SDK is currently available in TypeScript, with more languages coming soon. If you are interested in a language that is not listed, please reach out to us in the #dev-tools channel in the Avalanche Discord.
GitHub Repository
SDK Installation
npm add @avalanche-sdk/interchainpnpm add @avalanche-sdk/interchainbun add @avalanche-sdk/interchainyarn add @avalanche-sdk/interchain zodNote
Yarn does not install peer dependencies automatically. You will need to install zod as shown above.
SDK Example Usage
import { createWalletClient, http } from "viem";
import { createICMClient } from "@avalanche-sdk/interchain";
import { privateKeyToAccount } from "viem/accounts";
import * as dotenv from 'dotenv';
// Load environment variables
dotenv.config();
// these will be made available in a separate SDK soon
import { avalancheFuji, dispatch } from "@avalanche-sdk/interchain/chains";
// Get private key from environment
const privateKey = process.env.PRIVATE_KEY;
if (!privateKey) {
throw new Error("PRIVATE_KEY not found in environment variables");
}
// Load your signer/account
const account = privateKeyToAccount(privateKey as `0x${string}`);
// Create a viem wallet client connected to Avalanche Fuji
const wallet = createWalletClient({
transport: http('https://api.avax-test.network/ext/bc/C/rpc'),
account,
});
// Initialize the ICM client
const icmClient = createICMClient(wallet);
// Send a message across chains
async function main() {
try {
const hash = await icmClient.sendMsg({
sourceChain: avalancheFuji,
destinationChain: dispatch,
message: 'Hello from Avalanche Fuji to Dispatch Fuji!',
});
console.log('Message sent with hash:', hash);
} catch (error) {
console.error('Error sending message:', error);
process.exit(1);
}
}
main();Refer to the code samples provided for each route to see examples of how to use them in the SDK. Explore routes here Data API, Metrics API & Webhooks API.
Is this guide helpful?