Tomasz Waszczyk
Tomasz Waszczyk

Reputation: 3149

Event pattern in Substrate

Event pattern in blockchain solutions is well known, could anyone from Substrate's Team link to the pattern in Substrate code?

I just want to understand the pattern in the context of Substrate framework and Rust language.

Upvotes: 4

Views: 808

Answers (2)

Shawn Tabrizi
Shawn Tabrizi

Reputation: 12434

Substrate uses an enum to represent events in the Runtime. Each module can create its own Events enum with the decl_event! macro, and the runtime combines all these seperate objects into a single "outer enum" which captures all possible events that could be emitted from your runtime.

Then, events are simply placed in storage until the beginning of the next block.

Front ends process the event storage item from block to block and can use the information provided in it to notify users when certain actions have occurred.

Here is a walk-through of the code in Substrate that follows an event being emitted and then placed in storage: What is the cost of event storage in substrate?

Upvotes: 6

JoshOrndorff
JoshOrndorff

Reputation: 1701

The concepts of using events in Substrate are similar to those of Ethereum where the pattern was first popularized. Code paths in your on-chain logic (pallet in Substrate, contract in Ethereum) can cause particular events to be emitted. Those events can be subscribed to from offchain for purposes of updating a UI or confirming a transaction executed as expected.

The Substrate Recipes demonstrates how to use events in a Substrate pallet https://substrate.dev/recipes/2-appetizers/4-events.html

Upvotes: 3

Related Questions