Update examples for 0.90 (#1225)

* Update examples for 0.90

* Fix number typo

* Adapth to use timestamp.now (blockPeriod now in all versions)
This commit is contained in:
Jaco Greeff
2019-07-29 20:19:52 +02:00
committed by GitHub
parent a322fad2e9
commit 9dd0c6cfd8
6 changed files with 11 additions and 9 deletions
@@ -15,7 +15,7 @@ async function main () {
// are found, the call itself returns a promise with a subscription that can be
// used to unsubscribe from the newHead subscription
const unsubscribe = await api.rpc.chain.subscribeNewHead((header) => {
console.log(`Chain is at block: #${header.blockNumber}`);
console.log(`Chain is at block: #${header.number}`);
if (++count === 256) {
unsubscribe();
@@ -8,7 +8,7 @@ async function main () {
// Subscribe to chain updates and log the current block number on update.
const unsubscribe = await api.rpc.chain.subscribeNewHead((header) => {
console.log(`Chain is at block: #${header.blockNumber}`);
console.log(`Chain is at block: #${header.number}`);
});
// In this example we're calling the unsubscribe() function that is being
@@ -10,14 +10,14 @@ async function main () {
const api = await ApiPromise.create();
// Make our basic chain state/storage queries, all in one go
const [accountNonce, blockPeriod, validators] = await Promise.all([
const [accountNonce, now, validators] = await Promise.all([
api.query.system.accountNonce(ALICE),
api.query.timestamp.blockPeriod(),
api.query.timestamp.now(),
api.query.session.validators()
]);
console.log(`accountNonce(${ALICE}) ${accountNonce}`);
console.log(`blockPeriod ${blockPeriod.toNumber()} seconds`);
console.log(`last block timestamp ${now.toNumber()}`);
if (validators && validators.length > 0) {
// Retrieve the balances for all validators
@@ -2,7 +2,7 @@
// Import the API, Keyring and some utility functions
const { ApiPromise } = require('@polkadot/api');
const { Keyring } = require('@polkadot/keyring');
const { ExtrinsicEra } = require('@polkadot/types/type');
const { createType } = require('@polkadot/types');
const BOB = '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty';
@@ -26,8 +26,10 @@ async function main () {
const currentHeight = signedBlock.block.header.number;
const blockHash = signedBlock.block.header.hash;
// NOTE By default the API will send mortal transactions, only explicitly construct
// if you wish to override the defaults
// construct a mortal era
const era = new ExtrinsicEra({ current: currentHeight, period: 10 });
const era = createType('ExtrinsicEra', { current: currentHeight, period: 10 });
// Create an extrinsic, transferring 12345 units to Bob
const transfer = api.tx.balances.transfer(BOB, 12345);
@@ -13,7 +13,7 @@ async function main () {
api.rpc.chain.subscribeNewHead()
))
.subscribe((header) => {
console.log(`Chain is at block: #${header.blockNumber}`);
console.log(`Chain is at block: #${header.number}`);
});
}
+1 -1
View File
@@ -12,7 +12,7 @@ async function main () {
api.rpc.chain.subscribeNewHead()
))
.subscribe((header) => {
console.log(`Chain is at block: #${header.blockNumber}`);
console.log(`Chain is at block: #${header.number}`);
});
// In this example we're calling the Overvables unsubscribe() //