Blocto
Search…
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

1
// Switch to BSC
2
const params = [{ chainId: '0x38' }]
3
await window.ethereum.request({
4
method: 'wallet_switchEthereumChain',
5
params: params
6
})
Copied!
Switching network will emit a chainChanged event.
1
window.ethereum.on('chainChanged', (chainId) => {
2
console.log(chainId) // 0x38 if it's BSC
3
})
Copied!
Last modified 4mo ago
Copy link