sebs / etherscan-api Goto Github PK
View Code? Open in Web Editor NEWA node.js wrapper for the etherscan api to fetch data and metadata from the ethereum blockchain
Home Page: https://sebs.github.io/etherscan-api/
License: MIT License
A node.js wrapper for the etherscan api to fetch data and metadata from the ethereum blockchain
Home Page: https://sebs.github.io/etherscan-api/
License: MIT License
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.
Which function in account can get the list of ERC1155?
It has been a while, was wondering if it is still in progress or you are done with this proj?
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.
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 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';
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.
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
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.
We have a bunch of integration tests on the api, but these are very slow and needlesly shaky.
Profit!
If you are willing to help or contribute! ;) Please do so .. I will open a branch soon
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!
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.
Please, increase axios request timeout in lib/init.js
While requesting account.balance for 20 account (see limitations it takes sometimes more 3000ms
Deprecated libs (querystring
)
//this one
var query = querystring.stringify({
mod, action, apiKey, bool
})
//change into this
const dat = new URLSearchParams({
mod, action, apiKey, bool
}).toString()
querystring
was deprecated at least since last LTS version 14.
cc @sebs
The KOVAN testnet API service URL has been updated to http://api-kovan.etherscan.io .
The previous API url http://kovan.etherscan.io will cease to function as of March 31, 2018
Also see:
https://ropsten.etherscan.io/apis
https://kovan.etherscan.io/apis
https://rinkeby.etherscan.io/apis
txlistinternal
method returns transactions that does not related to specified hash
10.0.5
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
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
Currently, the contract endpoint only returns the bytecode, is support for getting the code source of verified contracts something planned?
When trying to mock the requests with nock i get the issue of doubling the uri.
Code is:
nock('https://api.etherscan.io')
.get(`api`)
.query({
module: 'account',
action: 'balance',
tag: 'latest',
address: '0x8d144e6277d0c38047f79df1dfc8b78994c6aa86',
apiKey: 'YourApiKey'
})
.reply(200, responses.ethereumResponse);```
As per https://etherscan.io/apis#tokens, using the in the token balance method is deprecated, making the example confusing. I suggest changing it to
* @example
* var supply = api.account.tokenbalance(
* '0x4366ddc115d8cf213c564da36e64c8ebaa30cdbd',
* '',
* '0xe0b7927c4af23765cb51314a0e0521a9645f0e2a' // DGD contract address
* );
Got an error
Module not found: Error: Can't resolve 'fs' in '.../node_modules/restify-clients/lib
Should wrap them in an Error
so error handlers get what they usually expect
I do not found an example for getting total received amount on an eth address (not actual balance).
Can you help me?
Thanks !
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);
},
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 { }
Using this wrapper to make api call to etherscan to fetch balance of ropsten hd address. Always returns this error for some addresses.
does this module incorporate the rate limits for calling the etherscan api (max 5/s)?
Are you still working on this project? I have just tried to call the balance function and it is returning a different balance than that reported on the Ethereum Mainnet. Please advise. Thanks.
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)
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.:
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.
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
I use the api.account.txlist query the transaction list, but only find the transaction of eth, if i want query the other token like Erc20 (TCT), what should i do?
thanks for first
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!
this package would be dope with typescript types
I believe working behind a corporate proxy is a common scenario. And suggested by this blog, https://janmolak.com/node-js-axios-behind-corporate-proxies-8b17a6f31f9d, I hope to have an option to customize the httpsproxy for axios request when using the etherscan-api.
Hope it makes sense.
Thanks.
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 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.
I can see Goerli finally been added 2 months ago.
would it be possible to publish this change to NPM
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'));
connect ETIMEDOUT 74.86.151.162:443๏ผไธบไปไนไผ้พๆฅ่ถ ๆถ
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?
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
(Returned 'isError' values: 0=No Error, 1=Got Error)
(Returns up to a maximum of the last 10000 transactions only)
or
(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
(Returned 'isError' values: 0=No Error, 1=Got Error)
(Returns up to a maximum of the last 10000 transactions only)
or
(To get paginated results use page= and offset=)
Get "Internal Transactions" by Transaction Hash
(Returned 'isError' values: 0=Ok, 1=Rejected/Cancelled)
(Returns up to a maximum of the last 10000 transactions only)
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?
`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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.