File tree Expand file tree Collapse file tree 3 files changed +63
-0
lines changed Expand file tree Collapse file tree 3 files changed +63
-0
lines changed Original file line number Diff line number Diff line change
1
+ # EAC Counter
2
+
3
+ ## Installation
4
+
5
+ ` npm install eac-counter `
6
+
7
+ ## Usage
8
+
9
+ ``` js
10
+ import EacCounter from ' eac-counter' ;
11
+ const counter = await EacCounter .getTotalEthTransferred ();
12
+ ```
Original file line number Diff line number Diff line change
1
+ class EacCounter {
2
+ static async getTotalEthTransferred ( ) {
3
+ const baseUrl = `http://api.etherscan.io/api?module=account&action=txlist&startblock=0&endblock=99999999&sort=asc` ;
4
+ const timestampSchedulerUrl = `${ baseUrl } &address=0x09e0c54ed4cffca45d691d5eb7b976d650f5904c` ;
5
+ const blockSchedulerUrl = `${ baseUrl } &address=0x56efae8a6d07fb29c24e67d76f3eccac180cf527` ;
6
+
7
+ const urls = [ timestampSchedulerUrl , blockSchedulerUrl ] ;
8
+
9
+ let promises = [ ] ;
10
+
11
+ urls . forEach ( url => {
12
+ const resultPromise = fetch ( url ) . then ( async ( resp ) => {
13
+ const response = await resp . json ( ) ;
14
+
15
+ if ( response . status == "1" && response . message === "OK" ) {
16
+ const weiTransferred = response . result . reduce ( ( acc , tx ) => acc + parseInt ( tx . value ) , 0 ) ;
17
+ return weiTransferred / 1e18 ;
18
+ } else {
19
+ throw Error ( response . result ) ;
20
+ }
21
+ } ) ;
22
+ promises . push ( resultPromise ) ;
23
+ } ) ;
24
+
25
+ const values = await Promise . all ( promises ) ;
26
+ const totalEthTransferred = values . reduce ( ( acc , value ) => acc + parseFloat ( value ) , 0 ) ;
27
+
28
+ return totalEthTransferred ;
29
+ }
30
+ }
31
+
32
+ module . exports = EacCounter ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " eac-counter" ,
3
+ "version" : " 0.0.1" ,
4
+ "description" : " Shows how much ETH has been transferred using the Ethereum Alarm Clock Protocol" ,
5
+ "main" : " index.js" ,
6
+ "scripts" : {
7
+ "test" : " node index.js"
8
+ },
9
+ "repository" : {
10
+ "type" : " git" ,
11
+ "url" : " git+https://github.com/chronologic/eac-counter.git"
12
+ },
13
+ "author" : " Joseph Bagaric (github.com/Bagaric)" ,
14
+ "license" : " ISC" ,
15
+ "bugs" : {
16
+ "url" : " https://github.com/chronologic/eac-counter/issues"
17
+ },
18
+ "homepage" : " https://github.com/chronologic/eac-counter#readme"
19
+ }
You can’t perform that action at this time.
0 commit comments