-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathethDatasource.js
More file actions
40 lines (33 loc) · 1.08 KB
/
Copy pathethDatasource.js
File metadata and controls
40 lines (33 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const { RESTDataSource } = require("apollo-datasource-rest");
//Vitalik's Ethereum Address
const eth_address = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
//Etherscan Data Source Class
class EtherDataSource extends RESTDataSource {
constructor() {
super();
this.baseURL = "https://api.etherscan.io/api";
}
async etherBalanceByAddress() {
return this.get(
`?module=account&action=balance&address=${eth_address}&tag=latest&apikey=${process.env.ETHERSCAN_API}`
);
}
async totalSupplyOfEther() {
return this.get(
`?module=stats&action=ethsupply&apikey=${process.env.ETHERSCAN_API}`
);
}
// Get latest Ethereum price
async getLatestEthereumPrice() {
return this.get(
`?module=stats&action=ethprice&apikey=${process.env.ETHERSCAN_API}`
);
}
// Get estimated block confirmation time
async getBlockConfirmationTime() {
return this.get(
`?module=gastracker&action=gasestimate&gasprice=2000000000&apikey=${process.env.ETHERSCAN_API}`
);
}
}
module.exports = EtherDataSource;