Developers Home»how to guides»Tightly Coupling a Pallet

Tightly Coupling a Pallet

Goal

Learn how to use one pallet's capabilities from inside your pallet

Use Cases

Give your pallet access to the methods and types of another pallet.

Overview

Tight coupling two pallets may suit specific use cases where the outside pallet contains many types and methods common to those of the initial pallet. If this is not the case, it's recommended to use loose coupling instead. Read more about pallet coupling here.

Steps

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 getter function

In order to use a method from special_pallet, call it the following way:

// Get the members from the vec-set pallet
let who = special_pallet::Pallet::<T>::get();

The above snippet assumes that special_pallet contains a method called get().

Examples

Resources

Last edit: on

Was This Guide Helpful?
Help us improve