Files
api/docs/examples/04_generate_account/index.js
T
Luke Schoen f399bb6fd6 docs: Fixes #154 (#167)
* 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
2018-09-26 07:24:03 +02:00

33 lines
1.1 KiB
JavaScript
Executable File

const crypto = require('crypto');
const Keyring = require('@polkadot/util-keyring').default;
const u8aToHex = require('@polkadot/util/u8a/toHex').default;
const Encoder = new TextEncoder(); // always utf-8
// A fixed seed from an array
const SEED1 = new Uint8Array([
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, 0, 0
]);
// A fixed seed from a 32 chars string
const SEED2 = Encoder.encode('correct horse battery and staple');
const keyring = new Keyring();
const pair1 = keyring.addFromSeed(SEED1);
const pair2 = keyring.addFromSeed(SEED2);
console.log('Deterministic addresses (same for each run):');
console.log(`Address 1\t ${pair1.address()}\t Seed: ${u8aToHex(SEED1)}`);
console.log(`Address 2\t ${pair2.address()}\t Seed: ${u8aToHex(SEED2)}`);
// A random seed
const SEED = new Uint8Array(32);
console.log('Random Addresses (random for each run):');
for (var i = 3; i < 13; i++) {
Buffer.from(crypto.randomFillSync(SEED));
const pair3 = keyring.addFromSeed(SEED);
console.log(`Address ${i}\t ${pair3.address()}\t Seed: ${u8aToHex(SEED)}`);
}