File tree Expand file tree Collapse file tree 2 files changed +53
-0
lines changed
pages/guide/cosmwasm-core/architecture Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ export default withMermaid({
4848 items : [
4949 { text : 'Semantics' , link : '/guide/cosmwasm-core/architecture/semantics' } ,
5050 { text : 'Actor model' , link : '/guide/cosmwasm-core/architecture/actor-model' } ,
51+ { text : 'Events' , link : '/guide/cosmwasm-core/architecture/events' } ,
5152 { text : 'Gas' , link : '/guide/cosmwasm-core/architecture/gas' } ,
5253 { text : 'Transactions' , link : '/guide/cosmwasm-core/architecture/transactions' } ,
5354 ]
Original file line number Diff line number Diff line change 1+ [ Cosmos Events ] : https://docs.cosmos.network/v0.50/learn/advanced/events
2+
3+ <SectionLabel chapter =" core " section =" architecture " ></SectionLabel >
4+
5+ # Events
6+
7+ CosmWasm can emit [ Cosmos Events] . These events are stored in the block execution result as
8+ metadata, allowing the contract to attach metadata to what exactly happened during execution.
9+
10+ ::: tip :bulb : Tip
11+
12+ Some important details about the keys:
13+ - Whitespaces will be trimmed (i.e. removed from the beginning and end).
14+ - Empty keys (that include keys only consisting of whitespaces) are not allowed.
15+ - Keys _ can not_ start with an underscore '** _ ** ', such keys are reserved for ** wasmd** .
16+
17+ :::
18+
19+ By default, CosmWasm emits the ` wasm ` event to which you can add attributes like so:
20+
21+ ::: code-group
22+
23+ ``` Rust [wasm_event.rs]
24+ let response : Response <Empty > = Response :: new ()
25+ . add_attribute (" custom_attribute" , " value" );
26+ ```
27+
28+ :::
29+
30+ ## Custom events
31+
32+ As mentioned above, CosmWasm only emits the event ` wasm ` by default. If you want to emit other
33+ events, such as domain-specific events like ` user_added ` , you can construct a fully custom event and
34+ attach it to the response.
35+
36+ ::: tip :bulb : Tip
37+
38+ Note that those custom events will be prefixed with '** wasm-** ' by the runtime.
39+
40+ :::
41+
42+ ::: code-group
43+
44+ ``` Rust [custom_event.rs]
45+ let event = Event :: new (" custom_event" )
46+ . add_attribute (" custom_attribute" , " value" );
47+
48+ let response : Response <Empty > = Response :: new ()
49+ . add_event (event );
50+ ```
51+
52+ :::
You can’t perform that action at this time.
0 commit comments