7

Suppose my pallet implements a trait MyTrait so that it can be loosely coupled with another pallet. Suppose also that MyTrait::my_function() makes storage modifications, which I would like to notify users of.

Is it okay to emit an event in the implementation of this function, even though it will only be called indirectly by other pallets? Will the event be visible in this case?

2 Answers 2

11

Yes it is okay, and yes it definitely makes sense.

The most common example of this pattern can be found in the Balances pallet, where Balances events are emitted every time the Currency trait is called from another pallet.

This allows off-chain services like Exchanges track all movement of funds, even when other pallets are doing the interactions.

3

There are also examples for events that are not tied to extrinsics, or rather those submitted much earlier.

For instance the scheduler can perform an upgrade for a runtime approved via democracy. In this case events such as PreImageUsed and CodeUpdated are emitted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.