-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheth.js
32 lines (24 loc) · 852 Bytes
/
eth.js
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
const express = require('express');
const { Alchemy, Utils } = require('alchemy-sdk');
const EthDater = require('ethereum-block-by-date');
const cors = require("cors");
const apiKey = "d29w2BF_oUfScLxstMOU6vkh5QpnpKIu";
const settings = {
apiKey: apiKey
};
const alchemy = new Alchemy(settings);
const dater = new EthDater(
alchemy.core // Ethers provider, required.
);
const app = express();
app.use(cors());
/** route used for getting balance at given eth address at given point of time */
app.get('/balance/:address/:timestamp', async (req, res) => {
const { address, timestamp } = req.params;
let block = await dater.getDate(timestamp);
block = block['block']
let balance = await alchemy.core.getBalance(address, block);
balance = Utils.formatEther(balance);
res.json({ balance });
});
module.exports = app;