referrerpolicy=no-referrer-when-downgrade
frame_support::pallet_macros

Attribute Macro event

Source
#[event]
Expand description

Allows defining pallet events.

Pallet events are stored under the system / events key when the block is applied (and then replaced when the next block writes it’s events).

The Event enum can be defined as follows:

#[frame_support::pallet(dev_mode)]
mod pallet {
	#[pallet::pallet]
	pub struct Pallet<T>(_);

	#[pallet::config]
	pub trait Config: frame_system::Config {}

	#[pallet::event]
	#[pallet::generate_deposit(fn deposit_event)] // Optional
	pub enum Event<T> {
		/// SomeEvent doc
		SomeEvent(u16, u32), // SomeEvent with two fields
	}
}

I.e. an enum (with named or unnamed fields variant), named Event, with generic: none or T or T: Config, and optional w here clause.

Macro expansion automatically appends From<Event<Self>> bound to system supertrait’s RuntimeEvent associated type, i.e:

	#[pallet::config]
	pub trait Config: frame_system::Config<RuntimeEvent: From<Event<Self>>> {}

Each field must implement Clone, Eq, PartialEq, codec::Encode, codec::Decode, and Debug (on std only). For ease of use, bound by the trait Member, available in frame_support::pallet_prelude.

§Note on deprecation of Events

  • Usage of deprecated attribute will propagate deprecation information to the pallet metadata where the item was declared.
  • For general usage examples of deprecated attribute please refer to https://doc.rust-lang.org/nightly/reference/attributes/diagnostics.html#the-deprecated-attribute
  • It’s possible to deprecated either certain variants inside the Event or the whole Event itself. If both the Event and its variants are deprecated a compile error will be returned.
  • Usage of allow(deprecated) on the item will propagate this attribute to the generated code.
  • If the item is annotated with deprecated attribute then the generated code will be automatically annotated with allow(deprecated)

Documentation for this macro can be found at frame_support::pallet_macros::event.