2
pub fn development_config() -> Result<ChainSpec, String> {
    let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;

    Ok(ChainSpec::from_genesis(
        // Name
        "Development",
        // ID
        "dev",
        ChainType::Development,
        move || {
            testnet_genesis(
                wasm_binary,
                // Initial PoA authorities
                vec![authority_keys_from_seed("Mrisho")],
                // Sudo account
                get_account_id_from_seed::<sr25519::Public>("Mrisho"),
                // Pre-funded accounts
                vec![
                    get_account_id_from_seed::<sr25519::Public>("Mrisho"),
                    get_account_id_from_seed::<sr25519::Public>("Masanja"),


                ],
                true,
            )
        },
        // Bootnodes
        vec![],
        // Telemetry
        None,
        // Protocol ID
        None,
        // Properties
        None,
        // Extensions
        None,
    ))
}

pub fn local_testnet_config() -> Result<ChainSpec, String> {
    let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;

    Ok(ChainSpec::from_genesis(
        // Name
        "Local Testnet",
        // ID
        "local_testnet",
        ChainType::Local,
        move || {
            testnet_genesis(
                wasm_binary,
                // Initial PoA authorities
                vec![authority_keys_from_seed("Mrisho"), authority_keys_from_seed("Masanja")],
                // Sudo account
                get_account_id_from_seed::<sr25519::Public>("Mrisho"),
                // Pre-funded accounts
                vec![
                    get_account_id_from_seed::<sr25519::Public>("Mrisho"),
                    get_account_id_from_seed::<sr25519::Public>("Masanja"),

                ],
                true,
            )
        },
        // Bootnodes
        vec![],
        // Telemetry
        None,
        // Protocol ID
        None,
        // Properties
        None,
        // Extensions
        None,
    ))
}

In the node template I modified my chain spec.rs and generated json file and everything is well. But when I run my node via node-template --dev --tmp. Or via specifying the json file ./node-template —chain chain spec.json. The accounts which I defined they aren't present while viewing my node in the polkadot.js. Despite deleting them, the alice ,bob and other predefined accounts are the only visible accounts.

4
  • Do you have a link to your repo? Try reloading the browser after node restart.
    – Bruno
    Mar 5, 2022 at 0:02
  • My link github.com/MrishoLukamba/subzero-rust/tree/experinments. And yes ive tried reloading the browser and even start the node specifically annotating am using chainspec.json file but still Mar 5, 2022 at 10:06
  • You should share in the question above the changes to made to the chain specification, and how you are checking that the accounts do not exist.
    – Shawn Tabrizi
    Mar 6, 2022 at 1:03
  • I have modified and included the code sample Mar 6, 2022 at 11:36

2 Answers 2

2

The alice, bob and other predefined accounts are only visible despite deleting them.

This is just a behavior of the Polkadot JS UI when using a "development" chain.

Note in your chain spec definition, you have:

// Name
"Development",
// ID
"dev",
ChainType::Development,

These flags are triggering the Polakdot JS UI to automatically show you the accounts Alice, Bob, Charlie, etc... on your UI. To remove them, I believe you can change these flags to something which represents a "production" chain, like:

"My Chain",
"my_chain",
ChainType::Live,

Or, there is probably also a flag on the Polakdot JS API to hide the test accounts.

As for your custom accounts, the UI does not search for all accounts automatically. The behavior you are seeing with Alice, Bob, Charlie, etc... is specific to these test accounts. If you want to see the accounts you generated, you need to add these accounts to your UI manually.

Since you are using the get_account_id_from_seed function provided by the node, your accounts will have a predefined seed.

So your accounts private key will be:

bottom drive obey lake curtain smoke basket hold race lonely fit walk//Mrisho

And your public address should be:

5G4ecPFwBYybyX3YKvP1W5GuSgLXsof4cXYSJNWhJFEj3eT3

But note, that what you are doing is awful for production, since I just posted your private key, and everyone will know it using these functions.

1

The predefined accounts come from keyring which is special object in polkadot, don't ask me how they work it. To answer your question, to actually see your accounts, if you're using polkadot js apps, you need to tell your polkadot front end that you possess the secret seeds for them, which you can get via a tool like subkey. For example for the first account you'd run something like target/release/node-template key inspect //Mrisho which will provide you with the secret seed (provided you didn't change anything in the get_account_id_from_seed function.

Next add an account on polkadot using the secret seed, which in this case is 0x5b621680b5d950cb1365f01cbd163e930a3d9fdab97d0b6253309ebad79f2686.

You should be able to see your account now, with the balance you provided.

4
  • Thanks alot but what if also I want the predefined accounts of alice and bob to not show on the polkadot js. Because chain spec is the configuration for the genesis block and in my genesis block. I did not include those accounts? Mar 6, 2022 at 12:23
  • If you're using a custom chain spec they won't show up on the front end. If you are using a local install of polkadot js or on the web explorer, chances are the keyring accounts are cached and they need to be removed from cache in order not to show up. Default behaviour is that when you connect a polkadot js front end to a node, no accounts will show up other than the ones you put in. Try running it with a --chain chain spec and make sure you clean your caches. Mar 6, 2022 at 12:27
  • Cleared cache and restarted the browser and the node. Still the predefined accounts are still there Mar 6, 2022 at 13:38
  • And even if i query my pallet balances total issuance is not zero but at the page of accounts in polkadot js it says total issuance is zero. It is behaving very weird Mar 6, 2022 at 13:55

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.