ethers-io / ethers.js

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

Add bscscan for Etherscan Providers #1473

Closed mcastiglione777 closed 3 years ago

mcastiglione777 commented 3 years ago

Hello, please add bscscan (Binance Chain Etherscan) for Etherscan providers the base URL is https://api.bscscan.com/

I use ethers.js and I need to use this endpoint so I can add historical data support for Binance Smart Chain.

the file is this one: packages/providers/src.ts/etherscan-provider.ts

Right now the options are these: switch(name) { case "homestead": baseUrl = "https://api.etherscan.io"; break; case "ropsten": baseUrl = "https://api-ropsten.etherscan.io"; break; case "rinkeby": baseUrl = "https://api-rinkeby.etherscan.io"; break; case "kovan": baseUrl = "https://api-kovan.etherscan.io"; break; case "goerli": baseUrl = "https://api-goerli.etherscan.io"; break; default: throw new Error("unsupported network"); }

It should be like this:

    switch(name) {
        case "homestead":
            baseUrl = "https://api.etherscan.io";
            break;
        case "ropsten":
            baseUrl = "https://api-ropsten.etherscan.io";
            break;
        case "rinkeby":
            baseUrl = "https://api-rinkeby.etherscan.io";
            break;
        case "kovan":
            baseUrl = "https://api-kovan.etherscan.io";
            break;
        case "goerli":
            baseUrl = "https://api-goerli.etherscan.io";
            break;
        case "smartchain":
            baseUrl = "https://api.bscscan.com";
            break;
        default:
            throw new Error("unsupported network");
    }

Also, there should be a handler for getEtherPrice, like this: delete these two lines: if (this.network.name !== "homestead") { return 0.0; } url += "?module=stats&action=ethprice"; add: if (this.network.name !== "homestead" && this.network.name !== "smartchain") { return 0.0; } if (this.network.name == "smartchain") { url += "?module=stats&action=bnbprice"; } else { url += "?module=stats&action=ethprice"; }

Thank you very much Marco

ricmoo commented 3 years ago

Closing this in favour of #1204.

Please comment there, and include any additional information.

Thanks! :)