switchChain

Function using for switch network into web3 wallet

Wallets supported

  • MetaMask

  • CoinbaseWallet

  • Trust

Input parameters

MetaMask wallet

// JavaScript

const data = {
    wallet: 'MetaMask', // required
    rpc: '', // option
    chainId: 1, // required
    params: {} // option
}

CoinbaseWallet

// JavaScript

const data = {
    wallet: 'CoinbaseWallet', // required
    rpc: '', // option
    chainId: 1, // required
    params: {} // option
}

Trust wallet

// JavaScript

const data = {
    wallet: 'Trust', // required
    rpc: '', // option
    chainId: 1, // required
    params: {} // option
}

params - add network if this have't in wallet

// JavaScript

params:
{
     chainId: web3.utils.toHex(56),
     chainName: "BSC",
     nativeCurrency: {
         name: "BNB",
         symbol: "BNB,
         decimals: 18
     },
     rpcUrls: ""
}

Using

// JavaScript

const wasSwitch = await switchChain(data)

Return

Return true if network was switch success, else false.

Last updated