ποΈFRAME Pallet
FRAMPallets are individual pieces of runtime logic for us in FRAME runtimes.
substrate_ has a long list of pre-packages pallets, but you can also build your own or modify one built by the substrate_ team.
Pallet Structure
A pallet is composed of a few building blocks. These are:
No Std
The first line of code, always. It tells the rust compiler not to use Rust's standard library except when explicitly told so.
Substrate runtimes are compiled to WASM and a regular native binary so you do not have access to rust's standard library.
This means simple things like printing to the command line using println! will not compile.
Imports
This is where crates are imported, especially the substrate_ framework crates.
All pallets will import frame-support and frame-system
Declaration of the Pallet Type
A placeholder to implement traits and methods.
Runtime Configuration Trait
This is used to access features from other pallets, or constants that impact the pallet's behavior.
The Config trait allows you to do the above while keeping Generic Types so you can change define and use something called coin or votes from some other Pallet defined at runtime, but swapped with some other pallet with a runtime update later on.
Runtime Storage
Have some custom data you want on the chain for users or otherwise?
Runtime Storage is where you do that. You declare storage items you'd like to make accessible to runtime.
Runtime Events
Events are how you communicate back to people using the block chain like "transaction confirmed!" or "error! not enough cash!"
Hooks
This is where you'd build some logic that can be executed regularly in some context, for e.g. on_initialize.
Basically, your blockchain's equivalent to handling webhooks.
Extrensics (Dispatchable Calls)
These are functions that blockchain users can call. This is often called a Dispatchable Call.
decl_module!
This is the macro where dispatchable calls are composed.
A Little More on Each Topic
β¬οΈImportsβοΈRuntime Configuration TraitπΎRuntime StorageπRuntime EventsπHookπExtrinsics (Dispatchable Calls)Last updated