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 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.
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 Networks | Test Network | Layer |
---|---|---|
IMTBL_ZKEVM_MAINNET | No | Layer 2 |
IMTBL_ZKEVM_TESTNET | Yes | Layer 2 |
IMTBL_ZKEVM_DEVNET | Yes | Layer 2 |
ETHEREUM | No | Layer 1 |
SEPOLIA | Yes | Layer 1 |
// 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.
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 the network details
const info = await checkoutSDK.getNetworkInfo({ provider });
For further details on the returned values view NetworkInfo.