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 { 
const createConfig: (params: CreateConfigProps) => AlchemyAccountsConfig

Creates an AlchemyAccountsConfig object that can be used in conjunction with the actions exported from @account-kit/core.

The config contains core and client stores that can be used to manage account state in your application.

createConfig
} from "@account-kit/core";
import {
const sepolia: Chain
sepolia
,
const mainnet: Chain
mainnet
,
function alchemy(config: AlchemyTransportConfig): AlchemyTransport

Creates an Alchemy transport with the specified configuration options. When sending all traffic to Alchemy, you must pass in one of rpcUrl, apiKey, or jwt. If you want to send Bundler and Paymaster traffic to Alchemy and Node traffic to a different RPC, you must pass in alchemyConnection and nodeRpcUrl.

alchemy
} from "@account-kit/infra";
export const
const config: AlchemyAccountsConfig
config
=
function createConfig(params: CreateConfigProps): AlchemyAccountsConfig

Creates an AlchemyAccountsConfig object that can be used in conjunction with the actions exported from @account-kit/core.

The config contains core and client stores that can be used to manage account state in your application.

createConfig
({
// use this transport for all chains
transport: AlchemyTransport
transport
:
function alchemy(config: AlchemyTransportConfig): AlchemyTransport

Creates an Alchemy transport with the specified configuration options. When sending all traffic to Alchemy, you must pass in one of rpcUrl, apiKey, or jwt. If you want to send Bundler and Paymaster traffic to Alchemy and Node traffic to a different RPC, you must pass in alchemyConnection and nodeRpcUrl.

alchemy
({
apiKey: string
apiKey
: "ALCHEMY_API_KEY" }),
// this is the default chain
chain: Chain
chain
:
const sepolia: Chain
sepolia
,
chains: { chain: Chain; policyId?: string | string[]; transport?: AlchemyTransport; }[]
chains
: [
{
chain: Chain
chain
:
const mainnet: Chain
mainnet
,
// optional: sponsor gas for this chain
policyId: string
policyId
: "MAINNET_GAS_MANAGER_POLICY_ID",
}, {
chain: Chain
chain
:
const sepolia: Chain
sepolia
,
// optional: override the default transport for this chain
transport: AlchemyTransport
transport
:
function alchemy(config: AlchemyTransportConfig): AlchemyTransport

Creates an Alchemy transport with the specified configuration options. When sending all traffic to Alchemy, you must pass in one of rpcUrl, apiKey, or jwt. If you want to send Bundler and Paymaster traffic to Alchemy and Node traffic to a different RPC, you must pass in alchemyConnection and nodeRpcUrl.

alchemy
({
apiKey: string
apiKey
: "OTHER_API_KEY" }),
// optional: sponsor gas for this chain
policyId: string
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.

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.

import { 
function setChain(config: AlchemyAccountsConfig, chain: Chain): Promise<void>

Allows you to change the current chain in the core store. Note, this chain must be one of the chains configured in your original createConfig call.

setChain
} from "@account-kit/core";
import {
const mainnet: Chain
mainnet
} from "@account-kit/infra";
import {
import config
config
} from "./config";
await
function setChain(config: AlchemyAccountsConfig, chain: Chain): Promise<void>

Allows you to change the current chain in the core store. Note, this chain must be one of the chains configured in your original createConfig call.

setChain
(
import config
config
,
const mainnet: Chain
mainnet
);
import { 
const createConfig: (params: CreateConfigProps) => AlchemyAccountsConfig

Creates an AlchemyAccountsConfig object that can be used in conjunction with the actions exported from @account-kit/core.

The config contains core and client stores that can be used to manage account state in your application.

createConfig
} from "@account-kit/core";
import {
const sepolia: Chain
sepolia
,
const mainnet: Chain
mainnet
,
function alchemy(config: AlchemyTransportConfig): AlchemyTransport

Creates an Alchemy transport with the specified configuration options. When sending all traffic to Alchemy, you must pass in one of rpcUrl, apiKey, or jwt. If you want to send Bundler and Paymaster traffic to Alchemy and Node traffic to a different RPC, you must pass in alchemyConnection and nodeRpcUrl.

alchemy
} from "@account-kit/infra";
export const
const config: AlchemyAccountsConfig
config
=
function createConfig(params: CreateConfigProps): AlchemyAccountsConfig

Creates an AlchemyAccountsConfig object that can be used in conjunction with the actions exported from @account-kit/core.

The config contains core and client stores that can be used to manage account state in your application.

createConfig
({
transport: AlchemyTransport
transport
:
function alchemy(config: AlchemyTransportConfig): AlchemyTransport

Creates an Alchemy transport with the specified configuration options. When sending all traffic to Alchemy, you must pass in one of rpcUrl, apiKey, or jwt. If you want to send Bundler and Paymaster traffic to Alchemy and Node traffic to a different RPC, you must pass in alchemyConnection and nodeRpcUrl.

alchemy
({
apiKey: string
apiKey
: "ALCHEMY_API_KEY" }),
// this is the default chain
chain: Chain
chain
:
const sepolia: Chain
sepolia
,
chains: { chain: Chain; policyId?: string | string[]; transport?: AlchemyTransport; }[]
chains
: [
{
chain: Chain
chain
:
const mainnet: Chain
mainnet
,
// optional: sponsor gas for this chain
policyId: string
policyId
: "MAINNET_GAS_MANAGER_POLICY_ID",
}, {
chain: Chain
chain
:
const sepolia: Chain
sepolia
,
// optional: sponsor gas for this chain
policyId: string
policyId
: "SEPOLIA_GAS_MANAGER_POLICY_ID",
}, ], });