Basic instantiable pallets
There's gotta be a better way than re-writing the same pallet twice...
note
This guide is based on FRAME v1 macros.
#
GoalLearn how to configure instantiable pallets.
#
Use cases- A token chain hosts two independent cryptocurrencies.
- Governance has two (or more) houses which act similarly internally.
- A social network chain that maintains different treasuries.
#
OverviewThe premise of instantiable pallets is to provide separate storage items for a runtime that contains more than one reference to the same pallet. This can be useful in cases where you may need to reuse the logic provided by a single pallet. This recipe guides you through how to create two instances of the same pallet and how to configure their capabilities.
#
StepsInstance
type#
1. Implement the Instantiable pallets must call the decl_storage!
macro so that the Instance
type is created.
Add a generic type for Instance
in the Config trait, Event type, and Store trait. Learn more about how generic types work in Rust here. The code snippet below shows the modifications required for our pallet's Config
and Store
traits:
#
2. Configure your runtimeInclude two instances of mint_token
in runtime/src/lib.rs
: