2

I want create a custom token in Substrate by the name GGG and I want to use this token for each transaction fee instead of the default Substrate token. Can someone please guide me on how to change the native token in Substrate to my custom token GGG?

2 Answers 2

2

All you need to do is set a custom property for token symbol in the chainspec.rs file in the function where you generate the chainspec config. This is typically a function that goes by the name of development_config in the substrate node template. Here I've done it:

let mut props = Properties::new();

props.insert("tokenSymbol".into(), "FYR".into()); 

props.insert("tokenDecimals".into(), "6".into());

And then finally attach it to the ChainSpec props field :

Ok(ChainSpec::from_genesis( 
     // Name
     "Development", 
     // ID 
      "dev", 
      ChainType::Development, 
                 move || { 
                         testnet_genesis( 
                                 wasm_binary, 
                                 // Initial PoA authorities 
                                 vec![authority_keys_from_seed("Alice")], 
                                 // Sudo account 
                                 get_account_id_from_seed::<sr25519::Public>("Alice"), 
                                 // 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"), 
                                 ], 
                                 true, 
                         ) 
                 }, 
                 // Bootnodes 
                 vec![], 
                 // Telemetry 
                 None, 
                 // Protocol ID 
                 None, 
                 None, 
                 // Properties (*Attach your props here*)
                 Some(props), 
                 // Extensions 
                 None, 
         ))
2

You can create a function like this:

https://github.com/darwinia-network/darwinia/blob/2d1c1436594b2c397d450e317c35eb16c71105d6/node/service/src/chain_spec/darwinia.rs#L52-L61

Replace the names and the decimals with yours.

One more thing, this could be a Vec. So, you can register multiple tokens at one time. As my example shows, our chain has 2 native tokens.


Then pass it to your genesis:

https://github.com/darwinia-network/darwinia/blob/2d1c1436594b2c397d450e317c35eb16c71105d6/node/service/src/chain_spec/darwinia.rs#L334

3
  • I have to run parachain and do these step on that or i can do them on substrate node ?
    – Mr Coder
    Feb 8, 2023 at 9:16
  • You can write these codes in any Substrate chain's chain_spec. Relaychain and parachain, are all Substrate chains. Feb 8, 2023 at 9:35
  • @AurevoirXavier if we have 2 native tokens then how do we identify which symbol is assigned to which token e.g if we have different supplies and token specs?
    – Rehan
    Apr 8, 2023 at 21:20

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.