2

We would like to implement custom emitting of the native token, like 1 token per block. Can you point us where the minting happens using substrate? Which pallet implements it?

Also is there a way to implement max total supply of the native token?

1 Answer 1

2

For minting logic in Substrate you can use the fungible trait:

For example, you could use mint_into trait to mint:

Note: There is also the Currency trait but that is being deprecated in favor of the fungible trait.

Pallet-wise you can use pallet-balances - it is designed to store and manage your native currency.

Pallet balances sets the total issuance of your native currency in its GenesisBuild by adding up the amount that each "genesis" account has:

let total = self.balances.iter().fold(Zero::zero(), |acc: T::Balance, &(_, n)| acc + n);

<TotalIssuance<T, I>>::put(total);

These accounts can be endowed in the GenesisConfig.

For example in the Substrate node-template, you will see the following in the chain spec:

balances: BalancesConfig {
    // Configure endowed accounts with initial balance of 1 << 60.
    balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(),
},

If you spin up the node-template and check the totalIssuance, you will see the following:

For the development config there are four accounts:

// 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"),
],

1 << 60 is equivalent to 1,152,921,504,606,846,976

So pallet balance's total issuance will be 1,152,921,504,606,846,976 * 4 == 4,611,686,018,427,387,904 which is what you see in the attached screenshot.

Keep in mind totalIssuance can change, but it is up to you to define the logic when to change totalIssuance. You can simply not have any logic that will increment totalIssuance - hence giving it a "soft" cap.

Related post:

For doing something every block, you can use Substrate's on_initialize hook:

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.