Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: EtherscanProvider BinanceSmartChain baseURL #1204

Closed

Conversation

davidp94
Copy link

@davidp94 davidp94 commented Dec 16, 2020

@ricmoo What is your take on adding these ones? 🤔

@ricmoo
Copy link
Member

ricmoo commented Dec 19, 2020

Looking into this now... Are the API's compatible? I don't see the proxy actions available on the APIs for these services: https://bscscan.com/apis

@davidp94
Copy link
Author

davidp94 commented Dec 19, 2020 via email

@davidp94
Copy link
Author

davidp94 commented Dec 19, 2020 via email

@ricmoo ricmoo added the investigate Under investigation and may be a bug. label Jan 8, 2021
@ricmoo
Copy link
Member

ricmoo commented Apr 16, 2021

In the next minor version bump, I will abstract the URL methods, so this is easier to sub-class for a BscScanProvider to utilize the EtherscanProvider logic.

@ricmoo ricmoo added enhancement New feature or improvement. minor-bump Planned for the next minor version bump. on-deck This Enhancement or Bug is currently being worked on. and removed investigate Under investigation and may be a bug. labels Apr 16, 2021
@mcastiglione777
Copy link

Hi, as far as I can see, bscscan is a fork of Etherscan. If you try to use the same endpoints, the response is the same. The only difference I could find is that ethprice is bnbprice

https://api.bscscan.com/api?module=stats&action=bnbprice

Besides adding the networks to the list, I have found this code that needs to be changed in etherscan-provider.ts:

if (this.network.name !== "homestead") { return 0.0; }
url += "?module=stats&action=ethprice";

Should be something like this:

if (this.network.name !== "homestead" && this.network.name !== "bsc-mainnet") { return 0.0; }
if (this.network.name == "bsc-mainnet") {
url += "?module=stats&action=bnbprice";
} else {
url += "?module=stats&action=ethprice";
}

That's all the differences I could find.

Thank you,
Marco

@mcastiglione777
Copy link

Hi @ricmoo , can you check this out please

ricmoo added a commit that referenced this pull request May 14, 2021
@domtancredi
Copy link

Any update on this one? Would be good to be able to interface with the Binance Smart Chain

@felipecsl
Copy link

you can connect to BSC using ethers by just instantiating a JsonRpcProvider directly, eg.:

new JsonRpcProvider(
  "https://bsc-dataseed1.defibit.io/",
  {
    chainId: 56,
    name: "bsc-mainnet",
  }
)

@ricmoo
Copy link
Member

ricmoo commented May 25, 2021

The changes needed were made in 5.2 to make this easier and I have a local working version. I will get back to it once EIP-1559 is out, as that is a much higher priority feature.

I can post a gist later with the implementation if you want to start using it sooner.

@domtancredi
Copy link

That would be great, thank you! I'd love to be able to connect. If I use JsonRpcProvider, do I need to have the changes from your gist or no?

@ricmoo
Copy link
Member

ricmoo commented May 26, 2021

Here is the preliminary source (requires ethers 5.2.0 or above):

https://gist.github.com/ricmoo/77fe78869118dc41d654eea6696c45bc

Try it out and let me know if you have any issues with it. It has only had very minimal testing.

Thanks! :)

pull bot pushed a commit to shapeshift/ethers.js that referenced this pull request Jun 4, 2021
pull bot pushed a commit to shapeshift/ethers.js that referenced this pull request Jun 4, 2021
@mcastiglione777
Copy link

Hi Ricmoo, that's great, thank you! I will try it out.

@ricmoo
Copy link
Member

ricmoo commented Aug 24, 2021

This should now be available in the BSC ancillary package: https://github.com/ethers-io/ancillary-bsc

Try it out and let me know if you run across any problems.

Thanks! :)

@ricmoo ricmoo closed this Aug 24, 2021
@ricmoo ricmoo added ancillary-package Related to Ancillary packages fixed/complete This Bug is fixed or Enhancement is complete and published. and removed enhancement New feature or improvement. on-deck This Enhancement or Bug is currently being worked on. minor-bump Planned for the next minor version bump. labels Aug 24, 2021
@PaulRBerg
Copy link

Hey @ricmoo, is the ancillary-bsc package still the best way to instantiate a provider for BSC?

I'm on @ethersproject/providers v5.5.0.

@zemse
Copy link
Collaborator

zemse commented Nov 24, 2021

ancillary-bsc is pretty much the EtherscanProvider for BSC. Note that the default provider uses only a single provider for fallback.

If you are using this provider in a wallet for a purpose of resolving some critical info like ENS names, it would be better to use quorum between multiple sources (incase a node is compromised and imagine receivername.eth resolves to some different address).

import { BscscanProvider } from "@ethers-ancillary/bsc";
const provider1 = new BscscanProvider();

import { JsonRpcProvider, FallbackProvider } from '@ethersproject/providers';
const provider2 = new JsonRpcProvider('bsc-node-a.com')
const provider3 = new JsonRpcProvider('bsc-node-b.com')

const provider = new FallbackProvider([provider1, provider2, provider3], 2) // at least two responses should match

Docs for FallbackProvider

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ancillary-package Related to Ancillary packages fixed/complete This Bug is fixed or Enhancement is complete and published.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants