-
Notifications
You must be signed in to change notification settings - Fork 4
/
get_grants.js
43 lines (34 loc) · 1.16 KB
/
get_grants.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
const ethers = require('ethers');
const TokenGrant = require("@keep-network/keep-core/artifacts/TokenGrant.json")
const config = require('./config')
const infura = config.infura_secret || process.env.INFURA_API;
const network = config.network || 'homestead'
if (process.argv.length < 3 || !process.argv[2]) {
console.error('node get_grants.js [address]');
process.exit(1);
}
async function main() {
try {
const ip = new ethers.providers.InfuraProvider(network, infura);
let addr
try {
addr = ethers.utils.getAddress(process.argv[2])
} catch (err) {
console.error(`Invalid address supplied: ${err}`)
process.exit(1)
}
const grantContract = new ethers.Contract(TokenGrant.networks["1"].address, TokenGrant.abi, ip);
const grants = await grantContract.getGrants(addr);
let amount;
for (let i in grants) { // Just use the first grant with enough tokens
amount = await grantContract.availableToStake(grants[i]);
console.log(`Grant id ${grants[i]} has ${amount} tokens available to stake`);
}
} catch(err) {
console.error(`Could not authorize: ${err.message}`)
process.exit(1)
}
}
main().catch(err => {
console.error("error:", err);
})