1

I was contributing on pallet-assets and I found it hard to understand this syntax:

pub trait Config<I: 'static = ()>: frame_system::Config

Care to explain in details and examples?

2
  • This is because it is an instantiable pallet. Some pallets, like the assets pallet, allow for multiple instances of the same pallet.
    – Bruno
    May 12, 2022 at 20:25
  • 1
    @Mrisho, If you want to help this site, please put the effort to put appropriate tags on your questions. [substrate-node] tag on this question is not helpful or appropriate.
    – Shawn Tabrizi
    May 12, 2022 at 20:42

1 Answer 1

3

Let's break it down:

pub trait Config<I: 'static = ()>: frame_system::Config
---------------- +++++++++++++++   xxxxxxxxxxxxxxxxxxxx
  1. Every pallet has a trait Config which allows you to configure the requirements of that pallet. This should not be new to you, as every pallet has this.

  2. Some pallets are configured to be Instantiable. This allows the same Pallet to be used multiple times in the same runtime. The extra I trait allows the user to do this, and by default, if the user does not implement I, it will automatically be implemented to () which is default.

  3. All pallets also require that they inherit the frame_system::Config trait. This is also not new and something you will see in every pallet.

You can see usage of instances in Polkadot, where the Collective Pallet is used twice for two different collectives:

pub type CouncilCollective = pallet_collective::Instance1;
impl pallet_collective::Config<CouncilCollective> for Runtime { ... }


pub type TechnicalCollective = pallet_collective::Instance2;
impl pallet_collective::Config<TechnicalCollective> for Runtime { ... }

In the case of default these two forms of syntax are the same:

// these two lines are the same, and having both in
// your code would trigger an duplication error.
impl pallet_collective::Config for Runtime { ... }
impl pallet_collective::Config<()> for Runtime { ... }

See also: Why is there a "lifetime" generic parameter in pallet_treasury?

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.