Developers Home»how to guides»Basic Pallet Integration

Basic Pallet Integration

Goal

Learn 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.

Overview

This 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 pallets

Assuming a pallet called pallet_something is created, the first step is to import it in /runtime/src/lib.rs:

// Import your pallet.
pub use pallet_something;

2. Include it in /runtime/src/lib.rs

For local pallets

Configure your pallet's runtime implementation. Assuming the local pallet only has Event and Call types exposed to the runtime:

// Configure your pallet.
impl pallet_something::Config for Runtime {
    type Event = Event;
    type Call = Call;
}

Declare your pallet and the items it exposes in construct_runtime!, including the additional Pallet and Storage types for the runtime macro:

construct_runtime!(
    pub enum Runtime where
        Block = Block,
        NodeBlock = opaque::Block,
        UncheckedExtrinsic = UncheckedExtrinsic
    {
/* --snip-- */
        Something: pallet_something::{Pallet, Call, Storage, Event<T>},
/* --snip-- */
    }
);

For external pallets

The same pattern applies as for declaring a local pallet, except you must ensure you include all the types your pallet exposes. Additionally, you must include the relevant parameter types and constants. For examples of how to declare parameters and constants, see the pallet_timestamp code, is declared.

3. Update /runtime/Cargo.toml

For local pallets

In /runtime/Cargo.toml, include your pallet as a local dependency, include it in std and add runtime-benchmarks:

/* --snip-- */
[dependencies.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-- */
]

For external pallets

For example, if the pallet is hosted in crates.parity.io, adding it to the runtime would look like this:

[dependencies.pallet-external]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
rev = 'd6c33e7ec313f9bd5e319dc0a5a3ace5543f9617'
version = '3.0.0'
/* --snip-- */
runtime-benchmarks = [
    /* --snip */
    'pallet-external/runtime-benchmarks',
]
std = [
'pallet-external/std',
/* --snip-- */
]

Examples

Docs

Rust docs

Other

Last edit: on

Was This Guide Helpful?
Help us improve