Interchain Messaging
Interchain Messaging
Overview
Send arbitrary messages between Avalanche chains and subnets using the Teleporter protocol. Messages are encoded as strings and delivered cross-chain.
Create Client
import { createICMClient } from "@avalanche-sdk/interchain";
import { createAvalancheWalletClient } from "@avalanche-sdk/client";
import { privateKeyToAvalancheAccount } from "@avalanche-sdk/client/accounts";
import { avalancheFuji, dispatch } from "@avalanche-sdk/interchain/chains";
// Setup wallet
const account = privateKeyToAvalancheAccount("0x...");
const wallet = createAvalancheWalletClient({
account,
chain: avalancheFuji,
transport: { type: "http" },
});
const icm = createICMClient(wallet);
// Or with default chains
const icm = createICMClient(wallet, sourceChain, destinationChain);The wallet client's chain configuration must match the sourceChain used in
your interchain operations. For example, if you're sending messages from Fuji
testnet, ensure your wallet client is configured with the Fuji chain.
Mismatched chains will result in an "invalid sender" error.
Methods
Is this guide helpful?