Search code examples
substrate

Dispatching a Function Defined in Another Substrate FRAME Pallet


I am familiar with one mechanism for achieving the goal described in this question's title: passing a dispatchable call, which is written in its own pallet, as an argument when invoking an extrinsic that is written in another pallet, as in the Sudo pallet or the multi-sig capabilities defined in the Utility pallet. What are the other options for dispatching functions across pallets? To be specific, I would like to include a pallet, Pallet A, as Trait-bound type for another pallet, Pallet B, and then dispatch a function that is defined in Pallet B from within Pallet A.


Solution

  • The behavior of dispatching calls like the Utility or Sudo pallet only makes sense when you need to control the origin/filters to a truly arbitrary dispatchable function.

    If you have two specific pallets that want to interact with one another, using a Trait to couple them is the correct approach. You can see this behavior in Substrate master by looking at the ChangeMembers trait and how it is used across pallets like Collective, Membership, Society, Phragmen Elections, etc...

    Additionally, you can look at a much bigger trait like Currency and see that it basically exposes the transfer "extrinsic" through Currency::transfer, allowing any pallet to execute this function in its own context.

    So in summary:

    • Would recommend you move forward with a trait
    • Would not recommend you use call.dispatch for such a specific pallet to pallet interaction