ethers-io / ethers.js

Complete Ethereum library and wallet implementation in JavaScript.
https://ethers.org/
MIT License
7.93k stars 1.84k forks source link

Provider support for BSC #1113

Closed ShivamDev31 closed 4 years ago

ShivamDev31 commented 4 years ago

I was checking out the providers and it seems there is no support for BSC right now. So can we add provider support for BSC testnet(chainId: 97) and mainnet (chainId: 56)? Docs available here: https://docs.binance.org/smart-chain/wallet/metamask.html

zemse commented 4 years ago

You should be able to use BSC right away, using JsonRpcProvider, passing in the RPC url available from the docs.

const bscProvider = new ethers.providers.JsonRpcProvider('https://bsc-dataseed.binance.org/')

For the point of adding support, actually there are plenty of chains which you can find here https://chainid.network, so putting something explicitly would also mean the other chains also should be added, also it's possible that the team of the projects might want some thing to change like default rpc urls, so instead of storing data in every library it makes sense to have some common store of data like the chainid network.

If a wrapper class that expects passing in the name or chain id and it does a look up on chainid network site and then it spins up a JsonRpcProvider object would be it I think. But again there is a concern since chainid.network is a dns controlled thing, some authority might use this as an attack vector to maliciously change the output (for example a malicious rpc url) of a lookup.

ShivamDev31 commented 4 years ago

@zemse that actually makes sense. Thanks for the detailed explanation.

ricmoo commented 3 years ago

I've added a little package to also expose a provider built on top of Bscscan.com.

It's an early prototype for what ancillary packages will look like, but try it out: https://github.com/ethers-io/ancillary-bsc

:)