Every time when I start my parachain, I see Alice, Bob, Charlie, Dave,... etc and each of them has 1.1529 MUNIT on Polkadot.js.org's Accounts -> Accounts -> My Account page.
How does Polkadot.js.org get those initial account balances?
I found this code in chain_spec.rs in substrate-parachain-template repository https://github.com/substrate-developer-hub/substrate-parachain-template/blob/main/node/src/chain_spec.rs#L119 :
pub fn development_config() -> ChainSpec {
// the same code as in local_testnet_config() below, except:
// Name: "Development",
// ID : "dev",
// ChainType::Development
// Protocol ID and Properties: None,
}
pub fn local_testnet_config() -> ChainSpec {
// Give your base currency a unit name and decimal places
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "UNIT".into());
properties.insert("tokenDecimals".into(), 12.into());
properties.insert("ss58Format".into(), 42.into());
ChainSpec::from_genesis(
// Name
"Local Testnet",
// ID
"local_testnet",
ChainType::Local,
move || {
testnet_genesis(
// initial collators.
vec![
(
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_collator_keys_from_seed("Alice"),
),
(
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_collator_keys_from_seed("Bob"),
),
],
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
],
1000.into(),
)
},
// Bootnodes
Vec::new(),
// Telemetry
None,
// Protocol ID
Some("template-local"),
// Fork ID
None,
// Properties
Some(properties),
// Extensions
Extensions {
relay_chain: "rococo-local".into(), // You MUST set this to the correct network!
para_id: 1000,
},
)
}
fn testnet_genesis(
invulnerables: Vec<(AccountId, AuraId)>,
endowed_accounts: Vec<AccountId>,
root_key: AccountId,
id: ParaId,
) -> GenesisConfig {
system: SystemConfig { ... },
balances: hero_runtime::BalancesConfig {
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(),
},
parachain_info: hero_runtime::ParachainInfoConfig { parachain_id: id },
...
}
I see this balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(),
maps ALICE, BOB, etc.. to 1 << 60
, which uses Rust's left shift operator to make ( A << B ) equivalent to A*2^B
for example:
1000 << 2 returns 1000*(2^2) = 4000
1 << 60 returns 1*(2^60) = 1.152921505×10^18, which matches what I saw in Polkadot.js.org
But both development_config()
or local_testnet_config()
use this testnet_genesis()
to generate initial account balances.
When I ran my local parachain with a local relay chain as described in "Connect other chains" https://docs.substrate.io/tutorials/connect-other-chains/, was I running it through development_config()
or local_testnet_config()
?
Both those two config functions use testnet_genesis()
fn testnet_genesis(
invulnerables: Vec<(AccountId, AuraId)>,
endowed_accounts: Vec<AccountId>,
root_key: AccountId,
id: ParaId,
){ ... }
What determines this testnet_genesis()
id
argument to be 1000.into(),
or 2000.into(),
?
When running my parachain locally with relay chain, I need to reserve paraId 2000 as described in the above "Connect other chains" tutorial.
Does this paraId 2000 determine the testnet_genesis()
id argument to be 2000.into()
?