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
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,
))
You can create a function like this:
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:
-
I have to run parachain and do these step on that or i can do them on substrate node ?– Mr CoderCommented 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.– aurexav ♦Commented 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?– RehanCommented Apr 8, 2023 at 21:20