Attribute Macro frame_support_procedural::config

source ·
Expand description

The mandatory attribute #[pallet::config] defines the configurable options for the pallet.

Item must be defined as:

pub trait Config: frame_system::Config + $optionally_some_other_supertraits

I.e. a regular trait definition named Config, with the supertrait frame_system::pallet::Config, and optionally other supertraits and a where clause. (Specifying other supertraits here is known as tight coupling)

The associated type RuntimeEvent is reserved. If defined, it must have the bounds From<Event> and IsType<<Self as frame_system::Config>::RuntimeEvent>.

pallet::event must be present if RuntimeEvent exists as a config item in your #[pallet::config].

Optional: with_default

An optional with_default argument may also be specified. Doing so will automatically generate a DefaultConfig trait inside your pallet which is suitable for use with [#[derive_impl(..)] to derive a default testing config:

pub trait Config: frame_system::Config {
		type RuntimeEvent: Parameter
			+ Member
			+ From<Event<Self>>
			+ Debug
			+ IsType<<Self as frame_system::Config>::RuntimeEvent>;

		type BaseCallFilter: Contains<Self::RuntimeCall>;
	// ...

As shown above, you may also attach the #[pallet::no_default] attribute to specify that a particular trait item cannot be used as a default when a test Config is derived using the #[derive_impl(..)] attribute macro. This will cause that particular trait item to simply not appear in default testing configs based on this config (the trait item will not be included in DefaultConfig).

DefaultConfig Caveats

The auto-generated DefaultConfig trait:

  • is always a subset of your pallet’s Config trait.
  • can only contain items that don’t rely on externalities, such as frame_system::Config.

Trait items that do rely on externalities should be marked with #[pallet::no_default]


  • Any items that rely on externalities must be marked with #[pallet::no_default] or your trait will fail to compile when used with derive_impl.
  • Items marked with #[pallet::no_default] are entirely excluded from the DefaultConfig trait, and therefore any impl of DefaultConfig doesn’t need to implement such items.

For more information, see derive_impl.