-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
37 lines (30 loc) · 1.03 KB
/
index.js
File metadata and controls
37 lines (30 loc) · 1.03 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
const Web3 = require('web3');
const path = require('path');
var express = require("express");
var app = express();
const PORT = process.env.PORT || 3000
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
app.get('/',function(req, res) {
res.sendFile(path.join(__dirname+'/index.html'));
});
app.get("/wallet/:network/:address", async (req, res, next) => {
// validate address
const address = req.params.address;
const network = req.params.network;
const listOfNetworks = ["mainnet", "kovan", "rinkeby", "goerli", "ropsten"];
if(listOfNetworks.includes(network)) {
const web3 = new Web3(new Web3.providers.HttpProvider(`https://${network}.infura.io/v3/f2cc84ffee9345169758837187067a88`));
if(web3.utils.isAddress(address)) {
const walletBalance = await web3.eth.getBalance(address);
res.status(200).json({
"currentEthBalance": web3.utils.fromWei(walletBalance, "ether") + " ETH"
});
}
} else {
res.status(404).json({
"error": "Wrong request"
});
}
});