Skip to content

Add Pallets to the Runtime

Introduction

In previous tutorials, you learned how to create a custom pallet and test it. The next step is to include this pallet in your runtime, integrating it into the core logic of your blockchain.

This tutorial will guide you through adding two pallets to your runtime: the custom pallet you previously developed and the utility pallet. This standard Polkadot SDK pallet provides powerful dispatch functionality. The utility pallet offers, for example, batch dispatch, a stateless operation that enables executing multiple calls in a single transaction.

Add the Pallets as Dependencies

First, you'll update the runtime's Cargo.toml file to include the Utility pallet and your custom pallets as dependencies for the runtime. Follow these steps:

Update the runtime's Cargo.toml file to include the utility pallet and your custom pallets as dependencies. Follow these steps:

  1. Open the runtime/Cargo.toml file and locate the [dependencies] section. Add the pallets with the following lines:

    [dependencies]
    ...
    pallet-utility = { version = "38.0.0", default-features = false }
    custom-pallet = { path = "../pallets/custom-pallet", default-features = false }
    
  2. In the [features] section, add the pallets to the std feature list:

    [features]
    default = ["std"]
    std = [
        ...
    "pallet-utility/std",
    "custom-pallet/std",
    
  3. Save the changes and close the Cargo.toml file

Update the Runtime Configuration

Configure the pallets by implementing their Config trait and update the runtime macro to include the new pallets:

  1. Add the OriginCaller import:

    use super::OriginCaller;
    

  2. Implement the Config trait for both pallets at the end of the runtime/src/config/mod.rs file:

    // Configure utility pallet
    impl pallet_utility::Config for Runtime {
        type RuntimeEvent = RuntimeEvent;
        type RuntimeCall = RuntimeCall;
        type PalletsOrigin = OriginCaller;
        type WeightInfo = pallet_utility::weights::SubstrateWeight<Runtime>;
    }
    
    // Define counter max value runtime constant 
    parameter_types! {
        pub const CounterMaxValue: u32 = 100;
    }
    
    // Configure custom pallet
    impl custom_pallet::Config for Runtime {
        type RuntimeEvent = RuntimeEvent;
        type CounterMaxValue = CounterMaxValue;
    }
    
  3. Locate the #[frame_support::runtime] macro in the runtime/src/lib.rs file and add the pallets:

    // Create the runtime by composing the FRAME pallets that were previously configured.
    #[frame_support::runtime]
    mod runtime {
    ...
        #[runtime::pallet_index(51)]
        pub type Utility = pallet_utility;
    
        #[runtime::pallet_index(52)]
        pub type CustomPallet = custom_pallet;
    }
    

Recompile the Runtime

After adding and configuring your pallets in the runtime, the next step is to ensure everything is set up correctly. To do this, recompile the runtime using the following command:

cargo build --release

This command ensures the runtime compiles without errors, validates the pallet configurations, and prepares the build for subsequent testing or deployment.

Run Your Chain Locally

Launch your parachain locally and start producing blocks:

  1. Create a new chain specification file with the updated runtime:

    chain-spec-builder create -t development \
    --relay-chain paseo \
    --para-id 1000 \
    --runtime ./target/release/wbuild/parachain-template-runtime/parachain_template_runtime.compact.compressed.wasm \
    named-preset development
    
  2. Start the omni node with the generated chain specification:

    polkadot-omni-node --chain ./chain_spec.json --dev
    
  3. Verify you can interact with the new pallets using the Polkadot.js Apps interface. Navigate to the Extrinsics tab and check that you can see both pallets:

    • Utility pallet

    • Custom pallet

Where to Go Next

  • Tutorial Deploy on Paseo TestNet


    Deploy your Polkadot SDK blockchain on Paseo! Follow this step-by-step guide for a seamless journey to a successful TestNet deployment.

    Get Started

Last update: December 17, 2024
| Created: December 17, 2024