Links
Comment on page

Switch Chain

Switch the blockchain network to another one

Introduction

It supports Ethereum/BSC/Polygon/Avalanche injected at window.ethereum. Blocto follows eip-3326 and will not reload the webpage after switching the network.

Usage

// 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
})