Skip to content

Commit

Permalink
Merge pull request #48 from CosmWasm/aw/events-corrections
Browse files Browse the repository at this point in the history
Corrections of Cosmos Events
  • Loading branch information
aumetra authored Jun 17, 2024
2 parents a886ab9 + afe4618 commit fb23899
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/pages/core/architecture/events.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@
tags: ["core", "architecture"]
---

import { Callout } from "nextra/components";

# Events

CosmWasm can emit
[Cosmos Events](https://docs.cosmos.network/v0.50/learn/advanced/events). These
events are stored in the block as metadata, allowing the contract to attach
metadata to what exactly happened during execution.

<Callout>

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
for `wasmd`

</Callout>

By default CosmWasm emits the `wasm` event to which you can add context like so:

```rust filename="wasm_event.rs" template="core"
Expand All @@ -22,6 +35,10 @@ 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.

<Callout>
Note that those custom events will be prefixed with `wasm-` by the runtime.
</Callout>

```rust filename="custom_event.rs" template="core"
let event = Event::new("custom_event")
.add_attribute("custom_attribute", "value");
Expand Down

0 comments on commit fb23899

Please sign in to comment.