Basic pallet integration
A fundamental pattern that all runtime engineers should internalize over time.
#
GoalLearn the steps for integrating a pallet to your runtime.
#
Use cases- Including a custom pallet that implements an event and a call for runtime.
- Including a pallet from Crates.io to a runtime.
#
OverviewThis guide is an extension to the "Add a Pallet to Your Runtime" tutorial, intended as a resource for developers new to Substrate looking to quickly integrate a pallet to their runtime. It covers adding both local and external pallets to a runtime.
#
Steps#
1. Import your pallet#
For local palletsAssuming a pallet called pallet_something
is created, the first step is to import it in /runtime/src/lib.rs
:
/runtime/src/lib.rs
#
2. Include it in #
For local palletsConfigure your pallet's runtime implementation. Assuming the local pallet only has Event
and Call
types exposed to the runtime:
Then, declare your pallet and the items it exposes in construct_runtime!
, including the additional Module
and Storage
types for the runtime macro:
#
For external palletsThe same pattern applies as for declaring a local pallet, except you must ensure you include all the types your pallet exposes.
In addition, don't forget to include relevant parameter types and constants if relevant. See this examples on how pallet_timestamp
is declared.
/runtime/Cargo.toml
#
3. Update #
For local palletsIn /runtime/Cargo.toml
, include your pallet as a local dependency, include it in std
and add runtime-benchmarks
:
#
For external palletsAssuming the pallet is hosted in parity.crates.io, adding it to the runtime would look like this: