Switch Network

You can switch to the specified chainId chain through wallet_switchEthereumChain and wallet_addEthereumChain

try {
  await NaboxWallet.request({
    method: 'wallet_switchEthereumChain',
    params: [{ chainId: '0x1' }], // Hexadecimal chainId
  });
} catch (error) {
  if (error.code === 4902) { // The current chain does not support
    try {
      await NaboxWallet.request({
        method: 'wallet_addEthereumChain',
        params: [
          {
            chainId: '0x38',
            chainName: '...',
            rpcUrls: ['https://...']
          },
        ],
      });
    } catch (error) {
      consolle.log(error)
    }
  }
}

Last updated