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:
-
Open the
runtime/Cargo.toml
file and locate the[dependencies]
section. Add the pallets with the following lines: -
In the
[features]
section, add the pallets to thestd
feature list: -
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:
-
Add the
OriginCaller
import: -
Implement the
Config
trait for both pallets at the end of theruntime/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; }
-
Locate the
#[frame_support::runtime]
macro in theruntime/src/lib.rs
file and add the pallets:
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:
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:
-
Create a new chain specification file with the updated runtime:
-
Start the omni node with the generated chain specification:
-
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.
| Created: December 17, 2024