-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreadStorage.js
46 lines (36 loc) · 1.6 KB
/
readStorage.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
// Import the API
const { ApiPromise, WsProvider } = require('@polkadot/api');
// Our address for Alice on the dev chain
const ALICE = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
async function main () {
const provider = new WsProvider('ws://127.0.0.1:8546');
// Create our API with a default connection to the local node
const api = await ApiPromise.create({provider});
// Make our basic chain state/storage queries, all in one go
const [{ nonce: accountNonce }, now, validators] = await Promise.all([
api.query.system.account(ALICE),
api.query.timestamp.now(),
api.query.session.validators()
]);
console.log(`accountNonce(${ALICE}) ${accountNonce}`);
console.log(`last block timestamp ${now.toNumber()}`);
let { data: { free: previousFree }, nonce: previousNonce } = await api.query.system.account(ALICE);
console.log(`${ALICE} has a balance of ${previousFree}, nonce ${previousNonce}`);
let aliceData = await api.query.system.account(ALICE);
console.log("data " + aliceData);
if (validators && validators.length > 0) {
// Retrieve the balances for all validators
const validatorBalances = await Promise.all(
validators.map((authorityId) =>
api.query.system.account(authorityId)
)
);
// Print out the authorityIds and balances of all validators
console.log('validators', validators.map((authorityId, index) => ({
address: authorityId.toString(),
balance: validatorBalances[index].data.free.toHuman(),
nonce: validatorBalances[index].nonce.toHuman()
})));
}
}
main().catch(console.error).finally(() => process.exit());