Your guide to transactions, smart contracts and more
What are smart contract events and logs?
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. 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.
Events are contained within transaction receipts which are created as a result of a transaction. An event consists of a name and parameters.
Events are crucial to understanding activity that is taking place within transactions. It’s useful to use a block explorer like Sirato, where you can not only view events but also view events associated with transactions, tokens and smart contracts.
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 the Sirato Block Explorer’s 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.
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.
Become a web3 native by reading all of our Blockchain Explained articles.
Are you ready to adopt blockchain technology?
Our products and services make blockchain technology accessible for everyone
Sirato Blockchain Explorer
SaaS and on-prem blockchain data and analytics platform for Ethereum compatible, layer 2 and Polkadot networks.
Enterprise blockchain support
Production support for public and private blockchain networks built using Quorum and Hyperledger Besu clients.
Web3 Labs Newsletter
With the Web3 industry moving at such a fast pace, it can be time consuming to keep track of all the latest news and events.
Subscribe to our newsletter and you'll receive regular insights and updates relating to enterprise blockchain in one place.