* Move triple backticks onto new line so it doesn't break the code snippet formatting
* Add newline between dependency imports and variable declarations
* Add link to relevant line of Github repo of eventemitter3 instead of the travis build directory
* Add full stop at end of sentence in line before `@example` in .ts files, since I noticed that was the only difference between code snippet in docs that was being rendered correctly and one that was not (if the docs were generated from it). Not sure if this actually makes any difference though, but it doesn't hurt to try. i.e. change `[[unsubscribe]]` to `[[unsubscribe]].`
* Add missing code syntax for `new Ws(defaults.WS_URL)`
* Add missing `*__example__*:`
* Add missing semi-colons throughout code
* Fix typos and some grammar
* Move import of external libraries i.e. `const BN = require('bn.js');` or `const crypto = require('crypto');` before `@polkadot` ones in code
* Change from `e` to `error` in catch blocks for readable documentation
33 lines
1.1 KiB
JavaScript
Executable File
33 lines
1.1 KiB
JavaScript
Executable File
const BN = require('bn.js');
|
|
const Api = require('@polkadot/api').default;
|
|
const WsProvider = require('@polkadot/api-provider/ws').default;
|
|
const storage = require('@polkadot/storage').default;
|
|
|
|
const provider = new WsProvider('ws://127.0.0.1:9944');
|
|
const api = new Api(provider);
|
|
|
|
async function getAccountIndex (address) {
|
|
return api.state.getStorage([storage.system.public.accountIndexOf, address]);
|
|
}
|
|
|
|
async function getValidators () {
|
|
return api.state.getStorage([storage.session.public.validators]);
|
|
}
|
|
|
|
async function getBlockPeriod () {
|
|
return api.state.getStorage([storage.timestamp.public.blockPeriod]);
|
|
}
|
|
|
|
async function main () {
|
|
const address = '5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaDtZ';
|
|
const validators = await getValidators();
|
|
const index = await getAccountIndex(address);
|
|
const blockPeriod = await getBlockPeriod();
|
|
|
|
console.log(`BlockPeriod: ${new BN(blockPeriod).toString(10)} seconds`);
|
|
console.log(`Account Index of ${address}: ${index.toString(10)}`);
|
|
console.log('Current validators', validators);
|
|
}
|
|
|
|
main().finally(_ => process.exit());
|