Event Logs: Learn how to Monitor Activities on the Blockchain

Smart contracts can emit events whenever specific functions are triggered! Discover how to easily read these event logs on Blockscout.

Event Logs: Learn how to Monitor Activities on the Blockchain

An Event log is a mechanism that allows smart contracts to emit information about their execution. Whenever a smart contract emits an event, the EVM generates a log entry that is stored in the transaction receipt, which is part of the blockchain data structure.

Event logs can monitor specific occurrences or state changes within a contract. They are particularly beneficial for off-chain applications (such as front-end interfaces) that aim to respond to on-chain activities without continuously polling the blockchain. This is crucial for smart contract developers to communicate with external applications and for data analysts who wish to track the activities of a smart contract.

Structure of an Event Log

A typical event log entry consists of an address, decoded input data, topics, and data.

  • Address - The address of the contract that emitted the event.
  • Decoded input data - Raw data in the event log broken down to make it human-readable.
  • Topics—Topics are used to filter and search for events efficiently. They are an array that can contain up to four indexed parameters.
  • Data - Non-indexed parameters stored as raw encoded data.

Read Event Logs in Blockscout

You can access the Event Logs in Blockscout by going to the transaction details page for any specific transaction. However, event logs are available only in transactions involving smart contracts with event statements, so they are not available in every transaction.

Let us read event logs with the example below;

Click on the transaction hash to see the transaction details, then click the Logs tab (0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984).

The image shows that each log has a reference number (1808, 1809) for its respective addresses. This transaction has multiple logs - we will focus on the first one (1808).

Address

The address shows that the transaction involves “CoW protocol:GPv2Settlement” at 1808.

Decode Input data 

  • The method ID (ed99827e) represents the function signature hash, identifying the specific function called within the contract.
  • Call represents the function called, in this case, the function called “Interaction”.
  • The function call's parameters are presented in table format for improved readability. The target address is indexed for efficient searching, while the value and selector provided were not indexed. The Data section contains the raw hexadecimal representation of the non-indexed value and selector parameters. 

Topics

Topics are like labels or tags attached to events, making it easy to find specific events quickly.

  • Topic 0 (Function Signature): This is the first topic, it is the Keccak-256 hash of the event signature.
  • Topic 1: This is the second topic, it is the indexed target address.

Data

This section contains the ABI-encoded values of the non-indexed parameters, which in this case are the “value” and the “selector.”

This event log records and communicates details about interactions facilitated by the "CoW Protocol: GPv2Settlement" contract, allowing external applications to track and react to these interactions.

Conclusion

Event logs are essential because they provide a transparent, immutable, and gas-efficient way for smart contracts to relay on-chain activities to off-chain systems. This facilitates real-time monitoring of actions such as token transfers, governance votes, or state changes. With Blockscout, users can effectively track contract interactions without having to scan the entire blockchain.