-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!-- please provide a detailed description of the changes made in this pull request. --> ## Description This PR adds docs for emit/event. It adds reference docs, and a section in effective Gno. More practical examples will be added to Gno By Example. Closes: #2003 <details><summary>Contributors' checklist...</summary> - [ ] Added new tests, or not needed, or not feasible - [ ] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [ ] Updated the official documentation or not needed - [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [ ] Added references to related issues and PRs - [ ] Provided any useful hints for running manual tests - [ ] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md). </details> --------- Co-authored-by: Lee ByeongJun <lbj199874@gmail.com>
- Loading branch information
Showing
4 changed files
with
140 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
--- | ||
id: events | ||
--- | ||
|
||
# Gno Events | ||
|
||
## Overview | ||
|
||
Events in Gno are a fundamental aspect of interacting with and monitoring | ||
on-chain applications. They serve as a bridge between the on-chain environment | ||
and off-chain services, making it simpler for developers, analytics tools, and | ||
monitoring services to track and respond to activities happening in Gno.land. | ||
|
||
Gno events are pieces of data that log specific activities or changes occurring | ||
within the state of an on-chain app. These activities are user-defined; they might | ||
be token transfers, changes in ownership, updates in user profiles, and more. | ||
Each event is recorded in the ABCI results of each block, ensuring that action | ||
that happened is verifiable and accessible to off-chain services. | ||
|
||
## Emitting Events | ||
|
||
To emit an event, you can use the `Emit()` function from the `std` package | ||
provided in the Gno standard library. The `Emit()` function takes in a string | ||
representing the type of event, and an even number of arguments after representing | ||
`key:value` pairs. | ||
|
||
Read more about events & `Emit()` in | ||
[Effective Gno](../effective-gno.md#emit-gno-events-to-make-life-off-chain-easier), | ||
and the `Emit()` reference [here](../../reference/stdlibs/std/chain.md#emit). | ||
|
||
## Data contained in a Gno Event | ||
|
||
An event contained in an ABCI response of a block will include the following | ||
data: | ||
|
||
``` json | ||
{ | ||
"@type": "/tm.gnoEvent", // TM2 type | ||
"type": "OwnershipChange", // Type/name of event defined in Gno | ||
"pkg_path": "gno.land/r/demo/example", // Path of the emitter | ||
"func": "ChangeOwner", // Gno function that emitted the event | ||
"attrs": [ // Slice of key:value pairs emitted | ||
{ | ||
"key": "oldOwner", | ||
"value": "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5" | ||
}, | ||
{ | ||
"key": "newOwner", | ||
"value": "g1zzqd6phlfx0a809vhmykg5c6m44ap9756s7cjj" | ||
} | ||
] | ||
} | ||
``` | ||
|
||
You can fetch the ABCI response of a specific block by using the `/block_results` | ||
RPC endpoint. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters