Multi-chain Apps
Account Kit supports multi-chain apps, allowing you to build applications that interact with multiple blockchains. This guide will show you how to set up your app to work with multiple chains.
Update your config
In order to support multiple chains in your app, the first thing you need to do is update your createConfig
call to include the chains you want to support.
import { createConfig } from "@account-kit/core";
import { sepolia, mainnet, alchemy } from "@account-kit/infra";
export const config = createConfig({
// use this transport for all chains
transport: alchemy({ apiKey: "ALCHEMY_API_KEY" }),
// this is the default chain
chain: sepolia,
chains: [
{
chain: mainnet,
// optional: sponsor gas for this chain
policyId: "MAINNET_GAS_MANAGER_POLICY_ID",
},
{
chain: sepolia,
// optional: override the default transport for this chain
transport: alchemy({ apiKey: "OTHER_API_KEY" }),
// optional: sponsor gas for this chain
policyId: "SEPOLIA_GAS_MANAGER_POLICY_ID",
},
],
});
Change chains
Once your app is configured to use multiple chains, you can switch between them at any time using the setChain
function.
example.ts
import { setChain } from "@account-kit/core";
import { mainnet } from "@account-kit/infra";
import { config } from "./config";
await setChain(config, mainnet);