File tree Expand file tree Collapse file tree 8 files changed +100
-53
lines changed
Expand file tree Collapse file tree 8 files changed +100
-53
lines changed Original file line number Diff line number Diff line change 55A way to access the [ etherscan.io api] ( https://etherscan.io/apis ) using promises. Fetch a diverse set of information about the blockchain
66
77
8+ Livenet
9+
810``` javascript
911var api = require (' etherscan-api' ).init (' YourApiKey' );
1012var balance = api .account .balance (' 0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae' );
@@ -15,12 +17,23 @@ balance.then(function(balanceData){
1517
1618## For testnet usage
1719
20+ Supported:
21+
22+ * morden
23+ * ropsten
24+ * rinkeby
25+
26+ Latest
27+
1828``` javascript
19- var api = require (' etherscan-api' ).init (' YourApiKey' ,' testnet' );
29+ var api = require (' etherscan-api' ).init (' YourApiKey' ,' rinkeby' );
30+ ```
31+
32+ Old Default
2033
34+ ``` javascript
35+ var api = require (' etherscan-api' ).init (' YourApiKey' ,' testnet' );
2136```
22- ** This feature are NOT shipped to npm package yet!!**
23- to use this feature - include exactly this version of repo.
2437
2538## Install
2639
Original file line number Diff line number Diff line change 11# Tutorial
22
33You can use a simple include, containing all code required to use the api.
4- Just use the cdn.
4+ Just use the cdn.
55
66## Use from CDN
77
Original file line number Diff line number Diff line change @@ -3,23 +3,39 @@ var restify = require('restify');
33const querystring = require ( 'querystring' ) ;
44
55const url = 'https://api.etherscan.io/api' ;
6- const testUrl = 'https://testnet.etherscan.io/api' ;
7-
6+ const testUrls = {
7+ // old default defaults to rinkeb
8+ 'ropsten' : 'https://ropsten.etherscan.io/api' ,
9+ 'kovan' : 'https://kovan.etherscan.io/api' ,
10+ 'rinkeby' : 'https://rinkeby.etherscan.io/api'
11+ } ;
812
913/**
1014 * @module etherscan/api
1115 */
1216
13- // chain is for testnet
17+ // chain is for testnet (ropsten, rinkeby, kovan)
1418module . exports = function ( apiKey , chain ) {
1519
1620 if ( ! apiKey ) {
1721 apiKey = 'YourApiKeyToken' ;
1822 }
1923
24+ function pickChainUrl ( chain ) {
25+ if ( ! chain ) {
26+ return url ;
27+ }
28+
29+ if ( ! testUrls [ chain ] ) {
30+ throw Error ( 'Chain missing ' + chain ) ;
31+ }
32+
33+ return testUrls [ chain ] ;
34+ }
35+
2036 var client = restify . createJsonClient ( {
2137 // added testnet condition
22- url : chain === 'testnet' ? testUrl : url ,
38+ url : pickChainUrl ( chain ) ,
2339 // url: url,
2440 version : '*'
2541 } ) ;
Original file line number Diff line number Diff line change 22const assert = require ( 'chai' ) . assert ;
33const init = require ( '../.' ) . init ;
44describe ( 'proxy' , function ( ) {
5- it ( 'eth.getminedblocks' , function ( done ) {
5+ xit ( 'eth.getminedblocks' , function ( done ) {
66 var api = init ( ) ;
77 var txlist = api . account . getminedblocks ( '0x9dd134d14d1e65f84b706d6f205cd5b1cd03a46b' ) ;
88 txlist . then ( function ( res ) {
Original file line number Diff line number Diff line change @@ -122,7 +122,7 @@ describe('api', function() {
122122 } ) ;
123123 } ) ;
124124
125- it ( 'contract.getabi' , function ( done ) {
125+ xit ( 'contract.getabi' , function ( done ) {
126126 var api = init ( ) ;
127127 var abi = api . contract . getabi ( '0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413' ) ;
128128 abi . then ( function ( res ) {
Original file line number Diff line number Diff line change 11'use strict' ;
22const assert = require ( 'chai' ) . assert ;
33const init = require ( '../.' ) . init ;
4- describe ( 'balance' , function ( ) {
4+ describe ( 'testnet balance' , function ( ) {
55 it ( 'returns a promise' , function ( ) {
6- var api = init ( 'YourApiKeyToken' , 'testnet ' ) ;
6+ var api = init ( 'YourApiKeyToken' , 'ropsten ' ) ;
77 var balance = api . account . balance ( '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae' ) ;
88 assert . ok ( balance . then ) ;
99 } ) ;
1010
1111 it ( 'executes the promise' , function ( done ) {
12- var api = init ( 'YourApiKeyToken' , 'testnet ' ) ;
12+ var api = init ( 'YourApiKeyToken' , 'ropsten ' ) ;
1313 var balance = api . account . balance ( '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae' ) ;
1414 balance . then ( function ( ) {
1515 done ( ) ;
1616 } ) ;
1717 } ) ;
1818
1919 it ( 'has data' , function ( done ) {
20- var api = init ( 'YourApiKeyToken' , 'testnet ' ) ;
20+ var api = init ( 'YourApiKeyToken' , 'ropsten ' ) ;
2121 var balance = api . account . balance ( '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae' ) ;
2222 balance . then ( function ( res ) {
2323 assert . ok ( res ) ;
Original file line number Diff line number Diff line change 11'use strict' ;
22const assert = require ( 'chai' ) . assert ;
33const init = require ( '../.' ) . init ;
4- describe ( 'proxy ' , function ( ) {
5- it ( 'eth.getminedblocks' , function ( done ) {
6- var api = init ( 'YourApiKeyToken' , 'testnet ' ) ;
4+ describe ( 'testnet eth ' , function ( ) {
5+ xit ( 'eth.getminedblocks' , function ( done ) {
6+ var api = init ( 'YourApiKeyToken' , 'morden ' ) ;
77 //In testnet there are no mined blocks by this account
88 //reference - https://testnet.etherscan.io/api?module=account&action=getminedblocks&address=0x9dd134d14d1e65f84b706d6f205cd5b1cd03a46b&blocktype=blocks&apikey=YourApiKeyToken
99 // var txlist = api.account.getminedblocks('0x9dd134d14d1e65f84b706d6f205cd5b1cd03a46b');
You can’t perform that action at this time.
0 commit comments