-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathethDatasource.js
More file actions
49 lines (36 loc) · 1.22 KB
/
Copy pathethDatasource.js
File metadata and controls
49 lines (36 loc) · 1.22 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
41
42
43
44
45
46
47
48
49
const { RESTDataSource } = require("apollo-datasource-rest");
// Vitalik's Ethereum Address
const eth_address = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
// Etherscan Data Source Class
class EtherDataSource extends RESTDataSource {
constructor() {
super();
// Base URL for Etherscan API
this.baseURL = "https://api.etherscan.io/api";
}
async etherBalanceByAddress() {
// Get account balance for an Ethereum address
return this.get(
`?module=account&action=balance&address=${eth_address}&tag=latest&apikey=${process.env.ETHERSCAN_API}`
);
}
async totalSupplyOfEther() {
// Get total ether supply
return this.get(
`?module=stats&action=ethsupply&apikey=${process.env.ETHERSCAN_API}`
);
}
async getLatestEthereumPrice() {
// Get latest ETH price
return this.get(
`?module=stats&action=ethprice&apikey=${process.env.ETHERSCAN_API}`
);
}
async getBlockConfirmationTime() {
// Get estimated block confirmation time
return this.get(
`?module=gastracker&action=gasestimate&gasprice=2000000000&apikey=${process.env.ETHERSCAN_API}`
);
}
}
module.exports = EtherDataSource;