⚑Events

Events are information that is emitted by transactions taking place on a blockchain.

A transaction taking place on-chain represents a change of state to the underlying blockchain ledger. As discussed in the section on transactions, there are three different types of transaction that can take place on Ethereum.

Those transactions that deal with deploying or transacting with a smart contract result in some kind of change of state which is dictated by the code of the smart contract. For instance, a transaction could transfer ownership of a token from one wallet address to another.

Transactions in Ethereum either succeed or fail, they cannot return a result. Hence in order to provide details of what has changed following a transaction, events can be emitted by the transaction to show what activity has taken place as a result of the transaction.

Events can be thought of as equivalent to a log statement. The developer of smart contracts specifies when they are to be created and the information that should be contained within.

In order to see events taking place in real-time, you can refer to the events view in Chainlens.

Events are contained within transaction receipts which are created as a result of a transaction. An event consists of a name and parameters.

In addition to the events view, you can also view events associated with transactions, tokens and smart contracts in Chainlens. Events are crucial to understanding activity that is taking place within transactions.

Events do have limits. It's not possible to have more than four named parameters (referred to as topics) associated with an event, and they are limited to 32 bytes in size. Arbitrary data can also be emitted by events, but it is not indexed like topics can be.

For instance, in the above example, there is an event name Approved which emits an event with three topics Owner, Spender and Value.

Events are very useful for querying specific activity as it takes place in real-time. For instance, using Chainlens' API backend, you can easily create listening for certain activities taking place on-chain such as token transfers.

Sharing information using events is cheaper than storing it within the dedicated storage used by smart contracts.

Summary

Events enable smart contracts to share details of activity taking place on-chain. They can be thought of as log statements inserted into smart contracts by developers to share information about the result of transactions taking place.

Events can have up to four named parameters associated with them (referred to as topics) which allow them to be easily searched and indexed. This ease of indexing coupled with their lower costs makes them very attractive for smart contract developers.

Last updated