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
This commit is contained in:
Luke Schoen
2018-09-26 07:24:03 +02:00
committed by Jaco Greeff
parent bd6cf112b5
commit f399bb6fd6
22 changed files with 160 additions and 152 deletions
+21 -22
View File
@@ -1,23 +1,22 @@
const Api = require('@polkadot/api').default
const WsProvider = require('@polkadot/api-provider/ws').default
const extrinsics = require('@polkadot/extrinsics').default
const encodeExtrinsic = require('@polkadot/extrinsics/codec/encode/uncheckedLength').default
const encodeLength = require('@polkadot/extrinsics/codec/encode/length').default
const Keyring = require('@polkadot/util-keyring').default
const storage = require('@polkadot/storage').default
const BN = require('bn.js')
const BN = require('bn.js');
const Api = require('@polkadot/api').default;
const WsProvider = require('@polkadot/api-provider/ws').default;
const extrinsics = require('@polkadot/extrinsics').default;
const encodeExtrinsic = require('@polkadot/extrinsics/codec/encode/uncheckedLength').default;
const Keyring = require('@polkadot/util-keyring').default;
const storage = require('@polkadot/storage').default;
const Encoder = new TextEncoder()
const keyring = new Keyring()
const provider = new WsProvider('ws://127.0.0.1:9944')
const api = new Api(provider)
const Encoder = new TextEncoder();
const keyring = new Keyring();
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])
return api.state.getStorage([storage.system.public.accountIndexOf, address]);
}
async function transfer (keyRingFrom, addressTo, amount) {
const nextAccountIndex = await getAccountIndex(keyRingFrom.address())
const nextAccountIndex = await getAccountIndex(keyRingFrom.address());
// encode the call for signing
const encoded = encodeExtrinsic(
@@ -25,19 +24,19 @@ async function transfer (keyRingFrom, addressTo, amount) {
nextAccountIndex,
extrinsics.staking.public.transfer,
[addressTo, amount]
)
);
await api.author.submitExtrinsic(encoded)
.catch(e => console.log)
.catch(e => console.log);
}
const Alice = keyring.addFromSeed(Encoder.encode('Alice '))
const addressBob = '5Gw3s7q4QLkSWwknsiPtjujPv3XM4Trxi5d4PgKMMk3gfGTE'
const amount = new BN(999) // on dev chain, the fee is 1, that makes it a round 1000
const Alice = keyring.addFromSeed(Encoder.encode('Alice '));
const addressBob = '5Gw3s7q4QLkSWwknsiPtjujPv3XM4Trxi5d4PgKMMk3gfGTE';
const amount = new BN(999); // on dev chain, the fee is 1, that makes it a round 1000
console.log(`Crafting and sending an extrinsic for Alice to send Bob ${amount} DOTs`)
console.log(`Crafting and sending an extrinsic for Alice to send Bob ${amount} DOTs`);
transfer(Alice, addressBob, amount)
.then(() => console.log('Done'))
.catch((e) => console.log(e))
.finally(_ => process.exit(0))
.catch((error) => console.log(error))
.finally(_ => process.exit(0));