Use tight pallet coupling
⚠️ WARNING: This page contains potentially outdated information. Reading it might still be useful, yet we suggest taking it with a grain of salt.
Please refer to the `polkadot-sdk-docs` crate for the most up-to-date documentation on this topic.
Tight coupling two pallets is a technique to write pallets that re-use types and methods from an existing pallet.
It is useful for breaking up some runtime logic into separate pallets that need access to common type and methods. To learn more about tight coupling and loose coupling between pallets, see pallet coupling.
This guide will show you how to use a method from an existing pallet inside your own.
Before you begin
This guide assumes you have a pallet that you would like to couple another pallet with. Use the template pallet if you don't yet have a pallet to work with.
-
Configure your workspace
Assume you want to use a pallet called
special-pallet
, which is a pallet in your local workspace. Import it by providing its path in your pallet'sCargo.toml
file:special-pallet = { path = '../special-pallet', default-features = false }
-
Add a trait bound to your pallet
Now all you need to do is create a trait bound around your pallet's configuration trait:
pub trait Config: frame_system::Config + special_pallet::Config { // --snip-- }
-
Use a getter function
In order to use a method from
special_pallet
, call it the following way:// Get the members from `special-pallet` pallet let who = special_pallet::Pallet::<T>::get();
The above snippet assumes that
special_pallet
contains a method calledget()
which returns a vector of account IDs.