3

I am trying to add Binance Main and test net Network through web3 js. I don't want that user to setup it manually. Did you guys any idea about that how to handle it?

1
  • 1
    AFAIK this is still not possible with the current Metamask API.
    – pwagner
    Mar 10 at 13:52
6

Use wallet_addEthereumChain method - https://docs.metamask.io/guide/rpc-api.html#other-rpc-methods

Example code:

window.ethereum.request({
method: 'wallet_addEthereumChain',
params: [{
chainId: '0x38',
chainName: 'Binance Smart Chain',
nativeCurrency: {
    name: 'Binance Coin',
    symbol: 'BNB',
    decimals: 18
},
rpcUrls: ['https://bsc-dataseed.binance.org/'],
blockExplorerUrls: ['https://bscscan.com']
}]
})
.catch((error) => {
console.log(error)
}) 
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.