Use tight pallet coupling

⚠️ Update Notice:

Please read Substrate to Polkadot SDK page first.


Please refer to the Rust Docs 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.

  1. 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's Cargo.toml file:

    special-pallet = { path = '../special-pallet', default-features = false }
  2. 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--
    }
  3. 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 called get() which returns a vector of account IDs.

Examples

Resources