When I start my Substrate blockchain, I want to initialize users with some free balance.
How can I achieve this?
What if my chain is already running and I do not want to restart it?
When I start my Substrate blockchain, I want to initialize users with some free balance.
How can I achieve this?
What if my chain is already running and I do not want to restart it?
Genesis Configuration
The best way to set up your Substrate users with some initial free balance is to update your
chain_spec.rs
file such that users are given units at the genesis block of your blockchain.This genesis configuration happens through the Balances module:
Note the
balances
configuration here where each of theendowed_accounts
are iterated, and their balance is set to1 << 60
(which reads 1 left shift 60, which is1152921504606846976
in decimal).For the
--dev
chain, theendowed_accounts
is just Alice, but you can add whatever accounts you want like this:Where the
account_key
function uses the inputted string to generate an sr25519 seed.Sudo Module
If you already have started a blockchain and you have the Sudo module enabled, then use can also make a call to the
set_balance
privileged function in the Balances module.This function will allow you to set the free and reserved balance of any account to any value.