* refactor: Destructure imports together from same source in example util-crypto 01 * refactor: Destructure imports together example util-crypto 02. Avoid using default import. Show data to user * refactor: Destructure imports together example util-crypto 03. Show data to user * refactor: Split import over two lines looks cleaner * fix: Address review comments. Update dependencies in examples
32 lines
1.0 KiB
JavaScript
Executable File
32 lines
1.0 KiB
JavaScript
Executable File
// Import Keyring class and utility function
|
|
const Keyring = require('@polkadot/keyring').default;
|
|
const stringToU8a = require('@polkadot/util/string/toU8a').default;
|
|
|
|
async function main () {
|
|
// Create account seed for Alice and Bob
|
|
const ALICE_SEED = 'Alice'.padEnd(32, ' ');
|
|
const BOB_SEED = 'Bob'.padEnd(32, ' ');
|
|
|
|
// Create an instance of the Keyring
|
|
const keyring = new Keyring();
|
|
|
|
// Create their pairs with account seeds. Add to keyring pair dictionary
|
|
keyring.addFromSeed(stringToU8a(ALICE_SEED));
|
|
keyring.addFromSeed(stringToU8a(BOB_SEED));
|
|
|
|
// Note that we did not use `addFromAddress` since it does not add the
|
|
// secret key to memory so we cannot later retrieve it with `getPairs`
|
|
|
|
// Retrieve all keyring pairs from the keyring pair dictionary
|
|
keyring
|
|
.getPairs()
|
|
.forEach((pair, index) => {
|
|
const address = pair.address();
|
|
|
|
console.log(`\nAccount with index #${index} has json: `,
|
|
JSON.stringify(keyring.toJson(address), null, 2));
|
|
});
|
|
}
|
|
|
|
main().catch(console.error).finally(_ => process.exit());
|