description |
---|
Switch the blockchain network to another one |
It supports Ethereum/EVMs/Layer2 injected at window.ethereum
. Blocto follows eip-3326 and will not reload the webpage after switching the network.
// Switch to BSC
const params = [{ chainId: '0x38' }]
await window.ethereum.request({
method: 'wallet_switchEthereumChain',
params: params
})
Switching network will emit a chainChanged
event.
window.ethereum.on('chainChanged', (chainId) => {
console.log(chainId) // 0x38 if it's BSC
})