Developers Home»how to guides»Configuring Genesis for Balances

Configuring Genesis for Balances

Information

This is intended for beginners who want to become familiar with customizing their chain. Not all configurations will follow the same approach. This is the most basic approach. Learn more in the related material section.

Goal

Learn how to customize a chain's genesis configuration for the balances pallet.

Use Cases

Initialize balances for endowed accounts.

Overview

Genesis configuration is a useful tool for testing chain behavior by defining an initial state for things such as accounts, balances, genesis for custom pallets, and more. Here is a simple guide on how to configure custom initial balances for a runtime, by modifying BalancesConfig in chainspec.rs.

Steps

1. Modify accounts

In chain_spec.rs, modify the accounts-to-amount map to apply it to the set of all endowed accounts (this is how every node template is set up):

 pallet_balances: Some(BalancesConfig {
        balances: endowed_accounts.iter().cloned().map(|k|(k, 1 << 60)).collect(),
}),

Alternatively, write out each account you would like to pre-seed, as shown below:

pallet_balances: Some(BalancesConfig {
        balances: vec![ (
        get_account_id_from_seed::<sr25519::Public>("Alice"),
        1 << 60
        ),
        (
        get_account_id_from_seed::<sr25519::Public>("Bob"),
        1 << 60
        ),
        ],
}),

2. Modify balances

By changing the right side value of the balances tuple, you can customize the amount of each account. See the Rust documentation to learn how this works. Let's modify things such that Alice's account is pre-seeded with 1<<10:

pallet_balances: Some(BalancesConfig {
        balances: vec![ (
        get_account_id_from_seed::<sr25519::Public>("Alice"),
        1 << 10  // <---- shift 10 decimals: 1024
        ),
        ],
}),

Examples

Rust docs

Last edit: on

Was This Guide Helpful?
Help us improve