Skip to main content

Switch networks

In this brief step-by-step guide we will use the Checkout SDK to ask a user to add the zkEVM network to the wallet and switch to this new network.


Supported network

The list of supported networks can be programmatically fetched using the getNetworkAllowList() function.

Get the supported networks listView on GitHub
// Get the list of default supported networks
const type = checkout.NetworkFilterTypes.ALL;
const supportedNetworks = await checkoutSDK.getNetworkAllowList({ type });
setSupportedNetworks(supportedNetworks.networks.map(network => network.name));

The GetNetworkAllowListResult result provides list of allowed networks with additional information (e.g. nativeCurrency) that can be used while building your application.

Switch to the network

To connect to the zkEVM network, your application needs to ask the user to switch to zkEVM network. This can be easily done using the switchNetwork() function.

info

If the user wallet hasn't been configured for zkEVM network yet, switchNetwork() will prompt the user to add the network details before switching to it.

Supported NetworksTest NetworkLayer
IMTBL_ZKEVM_MAINNETNoLayer 2
IMTBL_ZKEVM_TESTNETYesLayer 2
IMTBL_ZKEVM_DEVNETYesLayer 2
ETHEREUMNoLayer 1
SEPOLIAYesLayer 1
Switch to Immutable zkEVMView on GitHub
// Switch to Immutable zkEVM Testnet and update the provider
const chainId = checkout.ChainId.IMTBL_ZKEVM_TESTNET;
const switchResponse = await checkoutSDK.switchNetwork({ provider: connectedProvider, chainId });

// Update the provider
setConnectedProvider(switchResponse.provider);

The SwitchNetworkResult result provides the new provider.

caution

The provider returned by switchNetwork() should be used as the new, most updated provider. The previous provider can be discarded.

Get the network details

As final step, we are getting some of the current network details using the getNetworkInfo() function.

Get network detailsView on GitHub
// Get the network details
const info = await checkoutSDK.getNetworkInfo({ provider });

For further details on the returned values view NetworkInfo.