2

I followed this tutorial to build a local blockchain and everything worked fine.

Now I would like to change the account balances for instance 0 for all accounts.

By looking at this post, I thought that I just need to modify balances in chain_spec.rs:

balances: BalancesConfig {
        // Configure endowed accounts with initial balance of 1 << 60.
        balances: endowed_accounts.iter().cloned().map(|k| (k, 0)).collect(),
    },

However it doesn't work and the balance didn't change (still 1<<60 for Alice and Bob). I also tried purging the chain.

How can I modify the initial balances of Alice and Bob ?

1 Answer 1

3

Depends how you run your node you have to modify the testnet_genesis() function or the local_testnet_config().

To make the balance 0 is as your code (changing the 1 << 60 with 0):

balances: BalancesConfig {
        // Configure endowed accounts with initial balance of 1 << 60.
        balances: endowed_accounts.iter().cloned().map(|k| (k, 0)).collect(),
    },

This populates the accounts in the endowed_accounts list.

To add/remove accounts you have to modify the list you are sending in the parameters when calling one of this functions testnet_genesis() function or the local_testnet_config():

// Pre-funded accounts
            vec![
                get_account_id_from_seed::<sr25519::Public>("Alice"),
                get_account_id_from_seed::<sr25519::Public>("Bob"),
                get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
                get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
            ],

After the changes build and run the node again:

cargo build --release
cargo run --release -- --dev

If you set all the accounts with 0, you will see this error message

 'the balance of any account should always be at least the existential deposit.'

Be aware you need at least an account with more than the existential depostit, you can modify the EXISTENTIAL_DEPOSIT constant in the runtime: runtime/src/lib.rs.

1
  • thank you for your detailed answer :)
    – Asamartino
    Nov 23, 2022 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.