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.

1import { createConfig } from "@account-kit/core";
2import { sepolia, mainnet, alchemy } from "@account-kit/infra";
3
4export const config = createConfig({
5 // use this transport for all chains
6 transport: alchemy({ apiKey: "ALCHEMY_API_KEY" }),
7 // this is the default chain
8 chain: sepolia,
9 chains: [
10 {
11 chain: mainnet,
12 // optional: sponsor gas for this chain
13 policyId: "MAINNET_GAS_MANAGER_POLICY_ID",
14 },
15 {
16 chain: sepolia,
17 // optional: override the default transport for this chain
18 transport: alchemy({ apiKey: "OTHER_API_KEY" }),
19 // optional: sponsor gas for this chain
20 policyId: "SEPOLIA_GAS_MANAGER_POLICY_ID",
21 },
22 ],
23});

Change chains

Once your app is configured to use multiple chains, you can switch between them at any time using the setChain function.

Changing the chain will trigger state changes in your app (eg. the BundlerClient returned from getBundlerClient, the SmartAccountClient returned from getSmartAccountClient, etc). This is why it’s important to use the various watch* methods that subscribe to the state changes that impact them.

1import { setChain } from "@account-kit/core";
2import { mainnet } from "@account-kit/infra";
3import { config } from "./config";
4
5await setChain(config, mainnet);