-
Notifications
You must be signed in to change notification settings - Fork 5
/
getCrowdloanContAddress.ts
53 lines (43 loc) · 1.36 KB
/
getCrowdloanContAddress.ts
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
/*
Simple code snippet to fetch parachain crowdloan contribution
addresses and store them in a JSON file
*/
import { ApiPromise, WsProvider } from '@polkadot/api';
import * as fs from 'fs';
import yargs from 'yargs';
// Get input arguments
const args = yargs.options({
network: { type: 'string', demandOption: true, alias: 'n' },
}).argv;
// Create Provider
let wsProvider;
if (args['network'] === 'moonbeam') {
wsProvider = new WsProvider('wss://wss.api.moonbeam.network');
} else if (args['network'] === 'moonriver') {
wsProvider = new WsProvider('wss://wss.api.moonriver.moonbeam.network');
} else {
console.error('Network not supported');
process.exit();
}
const main = async () => {
// Wait for Provider
const api = await ApiPromise.create({
provider: wsProvider,
});
await api.isReady;
// Get the list of active collators
const rawRewardsList = await api.query.crowdloanRewards.accountsPayable.entries();
let rewardsAddresses = [];
rawRewardsList.forEach(([key, exposure]) => {
rewardsAddresses.push({
account: key.args.map((k) => k.toHuman()),
rewards: exposure.toHuman(),
});
});
// Save data to JSON file
const dataJSON = JSON.stringify(rewardsAddresses);
fs.writeFileSync(args['network'] + '_rewards_addresses.json', dataJSON, 'utf-8');
console.log('Done ✔️-- \n');
await api.disconnect();
};
main();