Basic Pallet Integration
This guide is an extension to the "Add a Pallet to Your Runtime" tutorial and explains how to quickly integrate both local and external pallets in a runtime.
You will learn how to include a custom internal pallet that implements an event and a call for runtime, and how to include an external pallet from Crates.io
to a runtime.
Import a pallet
Create a local pallet called
pallet_something
.Import this pallet by adding the following to
/runtime/src/lib.rs
:// Import your pallet. pub use pallet_something;
Configure your pallet's runtime implementation. Assume the local pallet only has the
Event
andCall
types exposed to the runtime. Add the following to/runtime/src/lib.rs
:// Configure your pallet. impl pallet_something::Config for Runtime { type Event = Event; type Call = Call; }
Declare your pallet and the items it exposes. Include the additional
Pallet
andStorage
types for the runtime macro. Inconstruct_runtime!
, add the following:construct_runtime!( pub enum Runtime where Block = Block, NodeBlock = opaque::Block, UncheckedExtrinsic = UncheckedExtrinsic { /* --snip-- */ Something: pallet_something::{Pallet, Call, Storage, Event<T>}, /* --snip-- */ } );
NOTE: To add an external pallet, you use a similar method to the one you used with the local pallet, but you must include all of the types your pallet exposes. You must also include the relevant parameter types and constants. For examples of how to declare parameters and constants, see
pallet_timestamp
.
Update
/runtime/Cargo.toml
Local pallets
In
/runtime/Cargo.toml
, include your pallet as a local dependency instd
and addruntime-benchmarks
. For example:# --snip-- pallet-something = { default-features = false, path = '../pallets/something' version = '3.0.0' # --snip-- [features] default = ['std'] runtime-benchmarks = [ # --snip-- 'pallet-something/runtime-benchmarks', ] std = [ 'pallet-something/std', # --snip-- ]
External pallets
The following is an example of how you would add an external pallet if the pallet is hosted on crates.parity.io:
[dependencies]
pallet-external = {default-features = false, git = "https://github.com/paritytech/substrate.git", version = "4.0.0-dev"}
# --snip--
runtime-benchmarks = [
/* --snip */
'pallet-external/runtime-benchmarks',
]
std = [
'pallet-external/std',
# --snip--
]