Building one block at a time
Master reading storage, working with constants, and decoding complex data structures. Understand how to efficiently query and interpret blockchain data.
0 of 5 lessons completed
Complete previous lesson
Complete previous lesson
Complete previous lesson
Complete previous lesson
Query runtime constants like block time, fees, and other chain parameters
Runtime constants are values that are baked into the blockchain's runtime and cannot be changed without a runtime upgrade.
// Access runtime constants
console.log('=== Runtime Constants ===');
// Block time (Babe module)
const blockTime = api.consts.babe.expectedBlockTime;
console.log('Expected block time:', blockTime.toString(), 'ms');
// Transaction fee constants
const existentialDeposit = api.consts.balances.existentialDeposit;
console.log('Existential deposit:', existentialDeposit.toString());
// Maximum block size
const maxBlockSize = api.consts.system.blockLength;
console.log('Max block size:', maxBlockSize.toString());
// Staking constants
const maxNominators = api.consts.staking.maxNominators;
console.log('Max nominators:', maxNominators.toString());
// Governance constants
const votingPeriod = api.consts.democracy.votingPeriod;
console.log('Voting period:', votingPeriod.toString());
// List all available constants
console.log('\n=== All Available Constants ===');
Object.keys(api.consts).forEach(module => {
console.log(`\n${module}:`);
Object.keys(api.consts[module]).forEach(constant => {
console.log(` ${constant}: ${api.consts[module][constant].toString()}`);
});
});
Create a function that displays all constants from a specific module
Run your code to see the output here...