fix: Fix promise examples minor typos in comments and variable name. Capitalise comments (#276)

This commit is contained in:
Luke Schoen
2018-10-13 08:56:27 +02:00
committed by Jaco Greeff
parent 1dd3cfce88
commit 85ebacb6de
5 changed files with 25 additions and 25 deletions
@@ -1,15 +1,15 @@
// required imports
// Required imports
const { ApiPromise } = require('@polkadot/api');
const { WsProvider } = require('@polkadot/rpc-provider');
async function main () {
// initialise the provider to connect to the local node
// Initialise the provider to connect to the local node
const provider = new WsProvider('ws://127.0.0.1:9944');
// create the API and wait until ready
// Create the API and wait until ready
const api = await ApiPromise.create(provider);
// retrieve the chain & node information information via rpc calls
// Retrieve the chain & node information information via rpc calls
const [chain, nodeName, nodeVersion] = await Promise.all([
api.rpc.system.chain(),
api.rpc.system.name(),
@@ -1,4 +1,4 @@
// API imports
// Import the API
const { ApiPromise } = require('@polkadot/api');
async function main () {
@@ -10,13 +10,13 @@ async function main () {
// Subscribe to the new headers on-chain. The callback is fired when new headers
// are found, the call itself returns a promise with a subscription that can be
// used to unsubscribe from the newHead subscription
const subsciptionId = await api.rpc.chain.newHead((header) => {
const subscriptionId = await api.rpc.chain.newHead((header) => {
console.log(`best #${header.blockNumber}`);
});
// id for the subscription, we can cleanup and unsubscribe via
// Id for the subscription, we can cleanup and unsubscribe via
// `api.chain.newHead.unsubscribe(subscriptionId)`
console.log(`subsciptionId: ${subsciptionId}`);
console.log(`subsciptionId: ${subscriptionId}`);
}
main().catch(console.error);
@@ -1,27 +1,27 @@
// import the Api
// Import the Api
const { ApiPromise } = require('@polkadot/api');
// the known account we want to use (available on dev chain, with funds)
// Known account we want to use (available on dev chain, with funds)
const Alice = '5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaDtZ';
async function main () {
// Create an wait for the API
// Create an await for the API
const api = await ApiPromise.create();
// Retrieve the initial balance. Since the call has no callback, it is simply a promise
// the resolves to the current on-chain value
// that resolves to the current on-chain value
let previous = await api.query.balances.freeBalance(Alice);
console.log(`${Alice} has an ${previous} balance`);
console.log(`${Alice} has a ${previous} balance`);
console.log(`You may leave this example running and start example 06 or transfer any value to ${Alice}`);
// Here we subscribe to any balance changes and updates the on-screen value
// Here we subscribe to any balance changes and update the on-screen value
api.query.balances.freeBalance(Alice, (current) => {
// Calculate the delta
const change = current.sub(previous);
// Only display positive value changes (Since we are pulling previous above already,
// the intiial balance change will also be zero)
// Only display positive value changes (Since we are pulling `previous` above already,
// the initial balance change will also be zero)
if (change.isZero()) {
return;
}
@@ -1,11 +1,11 @@
// Import the ApiPromise
// Import the API
const { ApiPromise } = require('@polkadot/api');
// Our address for Alice on the dev chain
const Alice = '5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaDtZ';
async function main () {
// Create out API with a default connection to the local node
// Create our API with a default connection to the local node
const api = await ApiPromise.create();
// Make our basic chain state/storage queries, all in one go
@@ -18,7 +18,7 @@ async function main () {
console.log(`accountNonce(${Alice}) ${accountNonce}`);
console.log(`blockPeriod ${blockPeriod.toNumber()} seconds`);
// get the balances for all validators
// Retrieve the balances for all validators
const validatorBalances = await Promise.all(
validators.map((authorityId) =>
api.query.balances.freeBalance(authorityId)
@@ -1,4 +1,4 @@
// Import our API, Keyring and some utility functions
// Import the API, Keyring and some utility functions
const { ApiPromise } = require('@polkadot/api');
const Keyring = require('@polkadot/keyring').default;
const u8aFromUtf8 = require('@polkadot/util/u8a/fromUtf8').default;
@@ -7,16 +7,16 @@ const ALICE_SEED = 'Alice'.padEnd(32, ' ');
const BOB_ADDR = '5Gw3s7q4QLkSWwknsiPtjujPv3XM4Trxi5d4PgKMMk3gfGTE';
async function main () {
// create an instance of the keyring
// Create an instance of the keyring
const keyring = new Keyring();
// Add Alice to our keyring (with the known seed for the account)
const alice = keyring.addFromSeed(u8aFromUtf8(ALICE_SEED));
// instantiate the API
// Instantiate the API
const api = await ApiPromise.create();
// retrieve the nonce for Alice, used to sign the transaction
// Retrieve the nonce for Alice, to be used to sign the transaction
const aliceNonce = await api.query.system.accountNonce(alice.address());
// Create a extrinsic, transferring 12345 units to Bob. We can also create,
@@ -24,10 +24,10 @@ async function main () {
// here we split it out for the sake of readability
const transfer = api.tx.balances.transfer(BOB_ADDR, 12345);
// sign the transaction using our account
// Sign the transaction using our account
transfer.sign(alice, aliceNonce);
// send the transaction and retrieve the resulting Hash
// Send the transaction and retrieve the resulting Hash
const hash = await transfer.send();
console.log(`transfer 12345 to Bob with hash ${hash}`);