Module 3: Storage & Constants

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.

5 lessons3-4 hoursBeginner

Course Progress

0%

0 of 5 lessons completed

1

Accessing Constants

20 min
Beginner
🔒

Complete previous lesson

🔒

Reading Storage

25 min
Beginner
🔒

Complete previous lesson

🔒

MultiKey & DoubleMap Storage

30 min
Intermediate
🔒

Complete previous lesson

🔒

Storage Subscriptions

25 min
Intermediate
🔒

Complete previous lesson

🔒

Storage Optimization

30 min
Advanced

Accessing Constants

Query runtime constants like block time, fees, and other chain parameters

1

Theory

Runtime Constants

Runtime constants are values that are baked into the blockchain's runtime and cannot be changed without a runtime upgrade.

Common Constants:

  • Block Time: Expected time between blocks
  • Fees: Transaction fee parameters
  • Limits: Various system limits and bounds
  • Parameters: Module-specific configuration

Code Example

// 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()}`);
  });
});

Challenge

Constants Explorer

Create a function that displays all constants from a specific module

Validation: Function correctly displays constants from the specified module

Try It Yourself

Code Editor

JAVASCRIPT
Loading...
31 lines

Console Output

Run your code to see the output here...