I want to have multiple currencies within the same runtime. There is Balances
pallet plugged into the default node template, but if I've got it right it can handle only one currency.
How can I re-use the pallet multiple times?
I want to have multiple currencies within the same runtime. There is Balances
pallet plugged into the default node template, but if I've got it right it can handle only one currency.
How can I re-use the pallet multiple times?
Pallets can be made instantiable which allows you to include multiple instances in the same runtime. The Substrate Recipes contain a writeup on creating instantiable pallets as well as these examples:
Conveniently, the Balances pallet that you're interested in is already instantiable as you can see from (among other places) its configuration trait.
For completeness, it's also worth mentioning that Substrate ships with the Assets pallet which is another approach to multiple tokens in a single runtime.
If you want exactly two tokens it's best to use two instances of the Balances pallet. If you want multiple tokens and the ability to add more later, Assets is best.
All pallets can be instantiated. This is specifically designed for modules that serve a purpose that suites the multi-instance model, including Balances
. A multi-currency chain is the textbook example of this feature. The collective pallet in substrate-node is already working like this. See how it is named twice (once for council
and once for technical committee
) in GenesisConfig
and even construct_runtime! {}
.
Here's a tutorial on how to do all of this, though expect some changes if you try in on substrate master, this is for 1.0. But the concepts should be the same.