Runtime Events
How to tell someone using your blockchain something happened.
Users of the application need feedback about what happened when they clicked something or interacted on your chain through a public endpoint you've given them.
Transactions can fail for any number of reasons, so your users need to know and that is handled through and Event
. Confirmations are similar: tell your user it went okay with an Event
.
Right, so my pallet should be able to emit Events?
Yep, pretty much without exception. Here's how:
In the Pallet
type Event
Add Event
type to the `Config:
decl_module!
And now add the decl_module!
("declare_module") macro to give access to the deposit_event()
method.
Reminder: the decl_module!
macro is the same we used for creating Dispatchable Calls
for a Pallet
.
decl_event!
decl_event!
("declare event") macro is the way Rust implements an event
We are showing generic types in these examples. The syntax for generic events requires the where
.
In the Runtime
We've defined a trait
in the Pallet
for Config
and so now it has to be implemented at runtime.
In your runtime lib.rs
file, add
The code above is simply specifying the type for Event
. Note the <T>
is not shown and that is because we are defining the concrete type to be implemented by the Pallet
we're configuring.
Add the events to the runtime build macro construct_runtime!
by adding:
Last updated