Skip to content

Commit 356aaed

Browse files
committed
Add index.js
1 parent be2db6b commit 356aaed

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
```

index.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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;

package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
}

0 commit comments

Comments
 (0)