Giter VIP home page Giter VIP logo

etherscan-api's People

Contributors

carletex avatar catzilla avatar dependabot[bot] avatar dibrovadev avatar dmitrypogodaev avatar jackbekket avatar jason-w123 avatar jason-wanxt avatar jsdelivrbot avatar kaizvn avatar m-tymchyk avatar mochimisu avatar morrislaptop avatar muxa avatar mvayngrib avatar noriega3 avatar peterferguson avatar sebs avatar snyk-bot avatar superern avatar tipsysquid avatar vicnaum avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

etherscan-api's Issues

Add snowtrace for avalanche mainnet and testnet (fuji)

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch [email protected] for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/etherscan-api/lib/pick-chain-url.js b/node_modules/etherscan-api/lib/pick-chain-url.js
index 067dcc5..ddb7fa9 100644
--- a/node_modules/etherscan-api/lib/pick-chain-url.js
+++ b/node_modules/etherscan-api/lib/pick-chain-url.js
@@ -5,9 +5,12 @@ const OTHER_API_URL_MAP = {
   rinkeby: 'https://api-rinkeby.etherscan.io',
   homestead: 'https://api.etherscan.io',
   arbitrum: 'https://api.arbiscan.io',
-  arbitrum_rinkeby: 'https://api-testnet.arbiscan.io'
+  arbitrum_rinkeby: 'https://api-testnet.arbiscan.io',
+  avalanche:'https://api.snowtrace.io',
+  avalanche_fuji: 'https://api-testnet.snowtrace.io',
 };
 
+
 /**
  * gets  the correct urls of the backend 
  * @param {string} chain 

This issue body was partially generated by patch-package.

Add support for explicit option for livenet

Currently we have:
require('etherscan-api').init(this.apikey, 'ropsten'); for ropsten
and
require('etherscan-api').init(this.apikey); for mainnet.

It would be nice adding support for:
require('etherscan-api').init(this.apikey, 'homestead'); for mainnet in order to keep calls similar.

Library throws error on empty txlist response

Hello again!

After updating to the latest version of the library I've started to experience some weird issue with the account.txlist request. When Etherscan API returns empty result, the library treats it as an incorrect response and throws the rejected promise with the cryptic "NOTOK" message.

That's where it happens:
https://github.com/sebs/etherscan-api/blob/master/lib/get-request.js#L39-L45

Also, it's incorrect to pass a string as a rejection argument. It should be new Error(returnMessage) instead.

The core problem though is that error message is not passed correctly, it should be: reject(new Error(data.message)) in this case.

Here's the value of such a response:

{
  "status": "0",
  "message": "No transactions found",
  "result": []
}

meteor integration

meteor integration gives an error at runtime (server side) :

W20161123-19:09:10.829(1)? (STDERR) /Users/xxxxxx/Documents/devel/xxxxx/node_modules/etherscan-api/lib/init.js:350 W20161123-19:09:10.830(1)? (STDERR) let params = { W20161123-19:09:10.830(1)? (STDERR) ^^^ W20161123-19:09:10.831(1)? (STDERR) W20161123-19:09:10.831(1)? (STDERR) SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode W20161123-19:09:10.831(1)? (STDERR) at exports.runInThisContext (vm.js:53:16) W20161123-19:09:10.832(1)? (STDERR) at Module._compile (module.js:373:25) W20161123-19:09:10.832(1)? (STDERR) at Object.Module._extensions..js (module.js:416:10) W20161123-19:09:10.833(1)? (STDERR) at Module.load (module.js:343:32) W20161123-19:09:10.833(1)? (STDERR) at Function.Module._load (module.js:300:12) W20161123-19:09:10.834(1)? (STDERR) at Module.require (module.js:353:17) W20161123-19:09:10.834(1)? (STDERR) at require (internal/module.js:12:17) W20161123-19:09:10.834(1)? (STDERR) at Object.<anonymous> (/Users/vincent/Documents/devel/meteor-songsforlife/node_modules/etherscan-api/index.js:2:14) W20161123-19:09:10.835(1)? (STDERR) at Module._compile (module.js:409:26) W20161123-19:09:10.835(1)? (STDERR) at Object.Module._extensions..js (module.js:416:10) => Exited with code: 1

and error :
W20161123-19:10:12.867(1)? (STDERR) /Users/xxxxxx/Documents/devel/xxxxxx/node_modules/etherscan-api/lib/init.js:510 W20161123-19:10:12.867(1)? (STDERR) let action = 'balance'; W20161123-19:10:12.867(1)? (STDERR) ^^^ W20161123-19:10:12.868(1)? (STDERR) W20161123-19:10:12.868(1)? (STDERR) SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode W20161123-19:10:12.868(1)? (STDERR) at exports.runInThisContext (vm.js:53:16) W20161123-19:10:12.869(1)? (STDERR) at Module._compile (module.js:373:25) W20161123-19:10:12.869(1)? (STDERR) at Object.Module._extensions..js (module.js:416:10) W20161123-19:10:12.869(1)? (STDERR) at Module.load (module.js:343:32) W20161123-19:10:12.870(1)? (STDERR) at Function.Module._load (module.js:300:12) W20161123-19:10:12.870(1)? (STDERR) at Module.require (module.js:353:17) W20161123-19:10:12.871(1)? (STDERR) at require (internal/module.js:12:17) W20161123-19:10:12.871(1)? (STDERR) at Object.<anonymous> (/Users/vincent/Documents/devel/meteor-songsforlife/node_modules/etherscan-api/index.js:2:14) W20161123-19:10:12.871(1)? (STDERR) at Module._compile (module.js:409:26) W20161123-19:10:12.872(1)? (STDERR) at Object.Module._extensions..js (module.js:416:10) => Exited with code: 1

this can be resolved in node_modules/etherscan-api/lib/init.js
by adding "use strict;" at the beginning of the functions

line 333 :

/** * @namespace */ stats: { /** * Returns the supply of Tokens * @param {string} tokenname - Name of the Token * @param {string} contractaddress - Address from token contract * @example * var supply = api.stats.tokensupply(null, '0x57d90b64a1a57749b0f932f1a3395792e12e7055'); * @returns {Promise.<object>} */ tokensupply(tokenname, contractaddress) { "use strict"; const module = 'stats'; const action = 'tokensupply';

line 501 :

/** * Returns the balance of a sepcific account * @param {string} address - Address * @example * var balance = api.account.balance('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae'); * @returns {Promise.<object>} */ balance(address) { "use strict"; const module = 'account'; let action = 'balance'; const tag = 'latest';

Future Plans

There are some issues to the codebase that make further development more heavy lifitng than I want it to be. I wanted to take time to outline further developments in this ticket.

Not a es6 codebase

The whole codebase is banking on node js and I would like it to be usable in a browser as well. best case no transpiling of any sort. In any case all code shall be pure es6 and use fetch for requests

hand crafted code

The whole code around the api is hand crafted and this research result in the docs were no clearly documented in a document but directly put into the codebase. This backfires now. It needs to be fixed with a machine readable definition of the API first. Swagger comes into mind and this homework has to be done. This way the requests can be generated from the definition and we can easier handle different response and error codes.

integration tests where unit tests are needed

We have a bunch of integration tests on the api, but these are very slow and needlesly shaky.

What is next?

  1. Definition of a swagger API description
  2. Adding first fixtures from the etherscan server to allow for local unit testing.
  3. Creating a client from the spec
  4. transpiling node js code from the es6 code
  5. Running test suites with teh created clients

Profit!

If you are willing to help or contribute! ;) Please do so .. I will open a branch soon

Promise returned was never settled

Hello!

Thank you for this useful module!

However, we have had an incident recently. I was hoping you could help us to understand what could have caused it.

We were using "etherscan-api": "^8.1.5" and calling proxy.eth_blockNumber() method. However, for some reason, the promise returned from the method was never settled (resolved or rejected), which blocked execution of our calling function.

I can see that you are passing a timeout of 10 seconds to axios by default (and we were not changing it). So it shouldn't be the problem. However, do you have tests for the timeout case?

Also, do you have any ideas what could have caused it? Any suggestions will be highly appreciated.

Thank you!

@sebs @m-tymchyk

Support arbitrum with etherscan-api

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch [email protected] for the project I'm working on.

It would be nice if we could use etherscan-api with Arbiscan out of the box.

Here is the diff that solved my problem:

diff --git a/node_modules/etherscan-api/lib/get-request.js b/node_modules/etherscan-api/lib/get-request.js
index c81c37b..c4e32fd 100644
--- a/node_modules/etherscan-api/lib/get-request.js
+++ b/node_modules/etherscan-api/lib/get-request.js
@@ -18,7 +18,9 @@ const TESTNET_API_URL_MAP = {
   ropsten: 'https://api-ropsten.etherscan.io',
   kovan: 'https://api-kovan.etherscan.io',
   rinkeby: 'https://api-rinkeby.etherscan.io',
-  homestead: 'https://api.etherscan.io'
+  homestead: 'https://api.etherscan.io',
+  arbitrum: 'https://api.arbiscan.io',
+  arbitrumTestnet: 'https://api-testnet.arbiscan.io'
 };
 
 module.exports = function(chain, timeout) {

This issue body was partially generated by patch-package.

replace querystring

Description:

Deprecated libs (querystring)

Code to reproduce:

//this one
var query = querystring.stringify({
  mod, action, apiKey, bool
})

//change into this
const dat = new URLSearchParams({
  mod, action, apiKey, bool
}).toString()

Reason

querystring was deprecated at least since last LTS version 14.

cc @sebs

Incorrect result of txlistinternal method

Description:

txlistinternal method returns transactions that does not related to specified hash

Package version:

10.0.5

Code to reproduce:

const api = require('etherscan-api').init('YourApiKeyToken');

const hash = '0x40eb908387324f2b575b4879cd9d7188f69c8fc9d87c901b9e2daaea4b442170';

const internal = api.account.txlistinternal(hash);

console.log(internal); // returns list of 10k transactions

Correct endpoint call will return only single one:
https://api.etherscan.io/api?module=account&action=txlistinternal&txhash=0x40eb908387324f2b575b4879cd9d7188f69c8fc9d87c901b9e2daaea4b442170&apikey=YourApiKeyToken

Reason:

Default values of parameters startblock and endblock are added to request, but they are not designed to be used in conjunction with the txhash parameter

Example App

  • using vue.js
  • using material design
  • showcases about 50% of the functionality
  • integration tested with latest changes
  • using a table

Mocking with nock

When trying to mock the requests with nock i get the issue of doubling the uri.

issue

Code is:

nock('https://api.etherscan.io')
  .get(`api`)
  .query({
    module: 'account',
    action: 'balance',
    tag: 'latest',
    address: '0x8d144e6277d0c38047f79df1dfc8b78994c6aa86',
    apiKey: 'YourApiKey'
  })
  .reply(200, responses.ethereumResponse);```

missing parameter in eth_call

looks like eth_call function is missing a 'data' param, check the code below:

      /**
      * Executes a new message call immediately without creating a transaction on the block chain
      * @param {string} to - Address to execute from
      * @param {string} tag - Content
      * @example
      * var res = api.proxy.eth_call('0xAEEF46DB4855E25702F8237E8f403FddcaF931C0', '0x70a08231000000000000000000000000e16359506c028e51f16be38986ec5746251e9724', 'latest');
      * @returns {Promise.<object>}
      */
      eth_call(to, tag) {
        const module = 'proxy';
        const action = 'eth_call';
        var query = querystring.stringify({
          module, action, apiKey, to, tag
        });
        return getRequest(query);
      },

Uncaught TypeError: Cannot read property 'maxSockets' of undefined

i tried like the demo code, but it error:

modules.js?hash=a607cd949caf1ffebfd396a8914ed52cfa5223d9:2341 Uncaught TypeError: Cannot read property 'maxSockets' of undefined
    at HttpClient.js (modules.js?hash=a607cd949caf1ffebfd396a8914ed52cfa5223d9:2341)
    at fileEvaluate (modules-runtime.js:353)
    at require (modules-runtime.js:248)
    at index.js (modules.js?hash=a607cd949caf1ffebfd396a8914ed52cfa5223d9:1689)
    at fileEvaluate (modules-runtime.js:353)
    at require (modules-runtime.js:248)
    at init.js (modules.js?hash=a607cd949caf1ffebfd396a8914ed52cfa5223d9:1019)
    at fileEvaluate (modules-runtime.js:353)
    at require (modules-runtime.js:248)
    at index.js (modules.js?hash=a607cd949caf1ffebfd396a8914ed52cfa5223d9:1002)

promise pending

Promise { }

Using this wrapper to make api call to etherscan to fetch balance of ropsten hd address. Always returns this error for some addresses.

Service Unavailable: Back-end server is at capacity

Hey! I'm not sure if this is the right place to file this issue, but I'm doing it anyway, because you probably know where to redirect this to.
Anyway, I've got these two errors in browser console (30 minutes ago everything worked just fine)

XMLHttpRequest cannot load https://api.etherscan.io/api?module=stats&action=ethprice&apikey=W26RIS92HKQWJHCMXTRRJT4SSRX2P1K8F5. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. The response had HTTP status code 503

GET https://api.etherscan.io/api?module=stats&action=ethprice&apikey=W26RIS92HKQWJHCMXTRRJT4SSRX2P1K8F5 503 (Service Unavailable: Back-end server is at capacity)

Support also other chains using an explorer compatible with etherscan

Hi,

on my projects I developed a wrapper for etherscan and I was curious to see if there was already an NPM package for this. I found this project.

I've seen you are developing a next gen = new version of this?

If so, please consider also to support other chains using etherscan (rebranded version) e.g.:

  • Fantom (ftmscan)
  • BSC (bscscan)
  • Polygon (polygonscan)
  • Avalanche (snowtrace.io)
  • etc.

Note: not all EVM chains cloned etherscan, so not all EVM chains have an API like those listed above, unluckily.
But the API works basically the same in all chains for what I know, maybe in some cases a specific call is not supported, else all same same, only change is the API URL.

I'd help if I had time, but as per usual I'm stressed in my project and will have to implement my wrapper on my own. I think supporting more chains doesn't require too much extra work, basically keep the explorerUrl a variable and replace it based on chain.

Also if using testnet, the suffix will be api-testnet.explorerUrl instead of api.explorerUrl.

Hope this helps, cheers and keep up the good work.

Incorrect error massage from `getRequest` function

Error that comes from proxy.eth_sendRawTransaction has incorrect error message

When I try to log error or use simple console.log, receive:

Error: [object Object]
at node_modules/etherscan-api/lib/get-request.js:44:25
{ not useful for this issue stack trace here }

getRequest method:

  function getRequest(query) {
    return new Promise(function(resolve, reject) {
      client.get('/api?' + query).then(function(response) {
        var data = response.data;

        console.log(data);
        if (data.status && data.status != 1) {
          return reject(data.message);
        }

        if (data.error) {
          return reject(new Error(data.error));
        }
        resolve(data);
      }).catch(function(error) {
        return reject(new Error(error));
      });
    });
  }

this is error structure example:

{ 
   jsonrpc: '2.0',
   error: 
    { 
      code: -32010,
      message: 'Transaction with the same hash was already imported.' 
   },
   id: 1 
}

Line with problem:

    if (data.error) {
          return reject(new Error(data.error));
        }

Error class constructor expects message string as first argument

The client returns incorrect gas price

Hello!

Thank you for this great library!

However, for some reason, the client returns the gas price different from calling the API directly.

If I open: https://api.etherscan.io/api?module=proxy&action=eth_gasPrice in browser the response would be 0xff2eb0d0, which is 4281250000 wei. However, when I do the request using the client: client.proxy.eth_gasPrice(), I'm always getting the same result: 0x3b9aca00, which is 1000000000 wei.

This leads to incorrect gas price calculated for our transactions. What could be causing this?

Thanks!

Fetch account balance at a specific block/date

Hi,
Is there an API to fetch account balance detail at a specified block or a date. I am working on a project where I need past account balance of an address.
I can see the tool at ethercan but need an API to fetch the same data.
[https://etherscan.io/balancecheck-tool?a=0xc0829421C1d260BD3cB3E0F06cfE2D52db2cE315
](Tool on etherscan)
Thanks

Goerli chain selection fails and uses the mainnet URL

Goerli network is not available on version 10.2.0 on NPM.

var etherscan = require('etherscan-api');
console.log(etherscan.pickChainUrl("goerli")); >> "api.etherscan.io"

This issue has already been resolved in PR: #113 but no new NPM package is available.

weird chain usage in init

right now i have to use

// initialize etherscan api client.
let etherscan = null;
if(config.get('api.etherscan.network') === 'main')
  etherscan = require('etherscan-api').init(config.get('api.etherscan.key'));
else
  etherscan = require('etherscan-api').init(config.get('api.etherscan.key'), config.get('api.etherscan.network'));

so if init() accepts an argument of 'mainnet' or so i could simply use;

const etherscan = require('etherscan-api').init(config.get('api.etherscan.key'), config.get('api.etherscan.network'));

ropsten Network Error

etherscan.init(ETHERSCAN_API_KEY, 'ropsten', 10000).contract.getabi(address)
Not only to call this method, other methods will also report the error, other test network or the main network has no problem
Does ropsten test network not work?

Gett list of transactions by address

Hi, thanks for this great library. I was wondering if you've implemented get "Get list of transactions by address" functionality? I couldn't see it in the docs. (Interestingly, as far as I can tell this isn't possible with web3, so the etherscanapi is needed for it).

Cheers,

From:
https://etherscan.io/apis#accounts

Get a list of 'Normal' Transactions By Address

[Optional Parameters] startblock: starting blockNo to retrieve results, endblock: ending blockNo to retrieve results

https://api.etherscan.io/api?module=account&action=txlist&address=0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a&startblock=0&endblock=99999999&sort=asc&apikey=YourApiKeyToken

(Returned 'isError' values: 0=No Error, 1=Got Error)

(Returns up to a maximum of the last 10000 transactions only)

or

https://api.etherscan.io/api?module=account&action=txlist&address=0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a&startblock=0&endblock=99999999&page=1&offset=10&sort=asc&apikey=YourApiKeyToken

(To get paginated results use page= and offset=)

Get a list of 'Internal' Transactions by Address

[Optional Parameters] startblock: starting blockNo to retrieve results, endblock: ending blockNo to retrieve results

https://api.etherscan.io/api?module=account&action=txlistinternal&address=0x2c1ba59d6f58433fb1eaee7d20b26ed83bda51a3&startblock=0&endblock=2702578&sort=asc&apikey=YourApiKeyToken

(Returned 'isError' values: 0=No Error, 1=Got Error)

(Returns up to a maximum of the last 10000 transactions only)

or

https://api.etherscan.io/api?module=account&action=txlistinternal&address=0x2c1ba59d6f58433fb1eaee7d20b26ed83bda51a3&startblock=0&endblock=2702578&page=1&offset=10&sort=asc&apikey=YourApiKeyToken

(To get paginated results use page= and offset=)

Get "Internal Transactions" by Transaction Hash

https://api.etherscan.io/api?module=account&action=txlistinternal&txhash=0x40eb908387324f2b575b4879cd9d7188f69c8fc9d87c901b9e2daaea4b442170&apikey=YourApiKeyToken

(Returned 'isError' values: 0=Ok, 1=Rejected/Cancelled)

(Returns up to a maximum of the last 10000 transactions only)

get calls periodically hang

periodically, get calls like account.balance(x) hang. because of the way the library is written, there is no way to pass timeout parameters to the calls, and there appear to be no timeout settings provided by default.

is there a way to set a default timeout, such that an error is thrown upon timeout?

how to use eth_call ?

`var eth_call = api.proxy.eth_call("0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413","getBuyPrice","");

eth_call.then(function(data1){
console.log(data1);
}).catch((err)=>{
console.log(JSON.stringify(err.message));
})`

I don't quite understand how to use it correctly?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.