In the context of a Substrate pallet, macros provided by the FRAME framework are extensively used to define and structure various aspects of the pallet. Here are the primary macro usages that you'll see often:
#[frame_support::pallet]
macro is used to declare the pallet module, indicating that it represents a FRAME pallet.#[pallet::config]
macro is used to define the pallet's configuration trait, specifying the required types and constants for the pallet.#[pallet::storage]
macro is used to define the pallet's storage items, such as storage values and storage maps.#[pallet::event]
macro is used to define the events that the pallet can emit.#[pallet::generate_deposit]
macro automatically generates the deposit_event function for emitting events, reducing boilerplate code.#[pallet::error]
macro is used to define the errors that the pallet can return.#[pallet::call]
macro is used to define the pallet's dispatchable functions (or Calls).By leveraging these macros, the Substrate pallet's code becomes more organized, readable, and maintainable. The macros abstract away many of the low-level details and provide a high-level, declarative way to define the pallet's components.
Furthermore, the use of macros helps in enforcing a consistent structure across different pallets. This consistency makes it easier for developers to understand and work with multiple pallets within a Substrate runtime.
Now that we've familiarized ourselves with the starter pallet code, let's dive into specifying the generic types necessary for our project.