Developers Home»How-to Guide»Basic Pallet Integration

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

  1. 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;
    
  2. Configure your pallet's runtime implementation. Assume the local pallet only has the Event and Call 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;
    }
    
  3. Declare your pallet and the items it exposes. Include the additional Pallet and Storage types for the runtime macro. In construct_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.

  1. Update /runtime/Cargo.toml

    Local pallets

    In /runtime/Cargo.toml, include your pallet as a local dependency in std and add runtime-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--
]

Examples

Last edit: on

Run into problems?
Let us Know