Add const example to app-js (#1424)

* Add const example to app-js

* Trigger Travis
This commit is contained in:
Stefanie Doll 2019-07-19 17:40:31 +02:00 committed by GitHub
parent 84153afd51
commit 7dffdb2e7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 6 deletions

View File

@ -0,0 +1,20 @@
// Copyright 2017-2019 @polkadot/app-js authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Snippet } from '@polkadot/app-js/types';
export const constsStakingParameters: Snippet = {
value: 'constsStakingParameters',
text: 'Get staking parameters',
label: { color: 'green', children: 'Consts', size: 'tiny' },
code: `// Get SRML staking parameters as consts
// 'parameter_types' were added to substrate with spec_version: 101.
// This example will throw an error if used with versions before that.
const bondingDuration = api.consts.staking.bondingDuration;
const sessionsPerEra = api.consts.staking.sessionsPerEra;
console.log('Staking bonding duration: ' + bondingDuration);
console.log('Staking sessions per era: ' + sessionsPerEra);`
};

View File

@ -19,7 +19,13 @@ import {
storageRetrieveInfoOnQueryKeys
} from './storage-examples';
import { extrinsicMakeTransfer } from './extrinsics-examples';
import {
constsStakingParameters
} from './consts-examples';
import {
extrinsicMakeTransfer
} from './extrinsics-examples';
const snippets: Snippet[] = [
rpcNetworkAuthoring,
@ -31,6 +37,7 @@ const snippets: Snippet[] = [
storageListenToBalanceChange,
storageListenToMultipleBalancesChange,
storageRetrieveInfoOnQueryKeys,
constsStakingParameters,
extrinsicMakeTransfer
];

View File

@ -9,17 +9,16 @@ export const storageGetInfo: Snippet = {
text: 'Get chain state information',
label: { color: 'blue', children: 'Storage', size: 'tiny' },
code: `// Get chain state information
// Make our basic chain state/storage queries, all in one go
// Make our basic chain state / storage queries, all in one go
const [minimumValidatorCount, validators] = await Promise.all([
const [now, minimumValidatorCount, validators] = await Promise.all([
api.query.timestamp.now(),
api.query.staking.minimumValidatorCount(),
api.query.session.validators()
]);
const transferFee = api.consts.balances.transferFee;
console.log('The current date is: ' + now);
console.log('The minimum validator count: ' + minimumValidatorCount);
console.log('transfer fee: ', transferFee);
if (validators && validators.length > 0) {
// Retrieve the balances for all validators