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
    Commented Mar 10, 2021 at 13:52

1 Answer 1

9

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
  • 2
    further to this chainlist.org, which is open source, has a large number of networks. Commented Nov 25, 2021 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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