2

When we launch substrate-front-end-template, the first thing one sees is a bunch of dummy accounts with some Balance, and I was under the impression that these accounts were being fetched from Genesis storage of the running chain. However, when I went into chain_spec.rs file and deleted all accounts, and even renamed some in the testnet_genesis function, I continue to see accounts, albeit with zero balance: enter image description here

On the console, keyring.getAccounts() returns these very accounts.

Here's what my ChainSpec looks like :

Ok(ChainSpec::from_genesis(
        "Development",
        "dev",
        ChainType::Development,
        move || {
            testnet_genesis(
                wasm_binary,
                vec![authority_keys_from_seed("Foundation")],
                get_account_id_from_seed::<sr25519::Public>("Foundation"),
                vec![
                    get_account_id_from_seed::<sr25519::Public>("Foundation"),
                ],
                true,
            )
        },
        // Bootnodes
        vec![],
        // Telemetry
        None,
        // Protocol ID
        None,
        // Properties
        Some(props),
        // Extensions
        None,
    ))

As you can see, no mention of alice, bob, charlie etc. accounts. I even scoured the entire node folder to find mention of these accounts but to no avail. Could someone tell me how to properly add new accounts, sudo accounts, etc. into my genesis configuration? Thanks.

RequireKeys
  • 466
  • 4
  • 15

2 Answers2

4

Accounts are just public keys in the node template. This means you can check every possible public key and it will return zero. But that doesn't mean that there is any state associated to this account. (assuming you have configured an existential deposit above 0).

If you want to add accounts on genesis, just check out the testnet_genesis. The endowed_accounts(4th argument) is what you are searching for. These are the accounts that get some balance at genesis. All of this code is chain depended and you can change it as you like.

bkchr
  • 621
  • 2
  • 5
  • Yes I've looked at testnet_genesis code as well, it's called from either the development_config or local_testnet_config functions. But what I can't find is a way to "create" accounts. The accounts that development_config creates are from seeds "Alice" and "Bob" etc. I would like to instead create them from pubkeys generated from say subkey & also display them on the front-end-template just like alice and bob accounts are. – RequireKeys Dec 30 '21 at 11:45
  • 1
    You can just add the public keys to this `endowed_accounts` vec. Just check this https://github.com/paritytech/substrate/blob/1ca6b68cf8cd35a1c58f790c28e51ae726272ee9/bin/node/cli/src/chain_spec.rs#L100 as an example. Regarding the display on the front end, you will need to add them manually to your address book in the ui. – bkchr Jan 02 '22 at 21:55
2

These test accounts are currently added if:

(The second check is purely for backward-compatability purposes)

As bkchr mentions there's no state stored against these accounts so they don't really exist until something is transfered into the accounts.

Squirrel
  • 1,189
  • 12
  • 15