Events
CosmWasm can emit Cosmos Events (opens in a new tab). These events are stored in the block execution result as metadata, allowing the contract to attach metadata to what exactly happened during execution.
💡
Some important details about the keys:
- Whitespaces will be trimmed (i.e. removed from the begin and end)
- Empty keys (that includes keys only consisting of whitespaces) are not allowed
- Keys cannot start with an underscore (
_
). These types of keys are reserved forwasmd
By default CosmWasm emits the wasm
event to which you can add attributes like so:
wasm_event.rs
let response: Response<Empty> = Response::new()
.add_attribute("custom_attribute", "value");
Custom events
As mentioned above, CosmWasm only emits the event wasm
by default. If you want to emit other
events, such as domain-specific events like user_added
, you can construct a fully custom event and
attach it to the response.
💡
Note that those custom events will be prefixed with
wasm-
by the runtime.custom_event.rs
let event = Event::new("custom_event")
.add_attribute("custom_attribute", "value");
let response: Response<Empty> = Response::new()
.add_event(event);