Associated readings:
Events
The available sources cover the majority that there is to be known about on-chain events. An important note that we would like to cover is how events interact with package versioning. The rule that events follow is that events will be emitted from their package of origin. This means that if you use an off-chain event listener you will subscribe to the events of a smart contract by referring to its original package ID.
There is a caveat nonetheless. What happens when you introduce a new event in a newer version? These events will be generated by their original package ID, however this time they do not correspond to the original smart contract package ID, but the version in which this got introduced. This can complicate matters and therefore in general we recomment developers to keep track of the event sources and describe them in their documentation.
To ensure that ALL events including newly introduced events in later package versions, you should export a wrapper event struct in your original package:
#![allow(unused)] fn main() { struct Event<T: copy + drop> has copy, drop { event: T, } }
This ensures that any subsequently added evenet will inherit the original package ID as its outer type:
#![allow(unused)] fn main() { event::emit(Event { event: SomeEvent {}}); }