forked from castframework/cast1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfos.js
86 lines (70 loc) · 2.05 KB
/
infos.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
var Web3 = require('web3');
const fs = require('fs');
const minimist = require('minimist');
const HDWalletProvider = require('@truffle/hdwallet-provider');
const utils = require('./dist/tools/utils')
module.exports = async function (callback) {
async function startGiveMoney() {
const argv = minimist(process.argv.slice(2));
const networkFolder = argv['network-folder'] ?? process.env['NETWORK_FOLDER'];
if (typeof networkFolder !== 'string') {
console.error('Network folder argument must be set')
process.exit(1)
}
let keys = {};
if (typeof networkFolder !== 'string') {
console.error('No network folder set');
process.exit(1)
}
const nodeFilePath = `${networkFolder}/ethereum/node.json`;
let nodeFile;
try {
nodeFile = fs.readFileSync(nodeFilePath, 'utf8');
} catch (e) {
console.error(
`Could not read node.json file for network: ${e.toString()}`,
);
process.exit(1)
}
try {
networkObject = JSON.parse(nodeFile);
} catch (e) {
console.error(
`Could not parse node.json file for network: ${e.toString()}`,
);
process.exit(1)
}
const keysFilePath = `${networkFolder}/ethereum/keys.json`;
let keysFile;
try {
keysFile = fs.readFileSync(keysFilePath, 'utf8');
} catch (e) {
console.error(
`Could not read keys.json file for network: ${e.toString()}`,
);
process.exit(1)
}
try {
keys = JSON.parse(keysFile);
} catch (e) {
console.error(
`Could not parse keys.json file for network: ${e.toString()}`,
);
process.exit(1)
}
try {
for (const [account, key] of Object.entries(keys)){
const publicKey = utils.getEthAddress(key);
const balance = await web3.eth.getBalance(publicKey);
console.log(
`${account}[${publicKey}]: ${web3.utils.fromWei(balance, 'ether')} ETH`,
);
};
} catch (err) {
console.log(err)
process.exit(1)
}
callback();
}
startGiveMoney();
}