Tight Coupling
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:Add a trait bound to your pallet
Now all you need to do is create a trait bound around your pallet's configuration trait:
Use a getter function
In order to use a method from
special_pallet
, call it the following way:The above snippet assumes that
special_pallet
contains a method calledget()
which returns a vector of account IDs.
Examples
Resources
Last updated