Under the Loom
Contents

§ 1.7 · Foundations · 5 min

Event Logs: The Chain's Debug Channel

Smart contracts announce what they did through event logs — topics, data and a bloom filter in every header. How logs work, why contracts cannot read them, and how analytics is built on them.

The Loom Desk ·

SHEET 40 · FOUNDATIONSUNDER THE LOOM
Fig. 1.7 — schematic. Watch the real thing in wevr.ai’s live tables.

When a smart contract transfers a token, swaps through a pool or records a vote, the state change itself is buried in contract storage — a vast key-value store that is expensive to search. To make their actions visible, contracts do something simpler: they write a log entry announcing what happened. These event logs are the main way the outside world — wallets, explorers, indexers and analytics platforms — learns what contracts did. Almost every on-chain dashboard you have ever seen is, underneath, a summary of event logs.

This chapter explains how logs are structured, where they live, what they cannot do, and how they become the readable events analysts query.

Emitting a log

Contracts written in Solidity declare events and emit them:

event Transfer(address indexed from, address indexed to, uint256 value);
emit Transfer(msg.sender, recipient, amount);

At the bytecode level, emitting compiles to one of five EVM opcodes, LOG0 to LOG4. The number indicates how many topics the log carries, from zero to four. Every log records:

  • the address of the contract that emitted it;
  • up to four topics, each 32 bytes;
  • a data field of arbitrary length.

Logging costs gas, but far less than writing to storage — which is part of why contracts use events generously.

Topics and data

For a standard event, the first topic is the event signature hash: the Keccak-256 hash of the event's name and parameter types, for example Transfer(address,address,uint256). That hash identifies what kind of event the log is, regardless of which contract emitted it — every ERC-20 transfer, from every token, shares the same first topic.

Parameters marked indexed go into the remaining topics, up to three of them. Non-indexed parameters are ABI-encoded together into the data field.

The distinction matters for searching. Topics can be filtered efficiently — "all Transfer events to this address" is a topic filter. Values in the data field cannot be filtered without decoding every log. Developers index the parameters people will want to search by.

Where logs live

Logs are not stored in the state. They are part of each transaction's receipt, alongside the transaction's status and gas used. Each block header contains a receipts root committing to all of the block's receipts, and a logs bloom — a compact probabilistic filter that lets a client quickly check whether a block might contain logs from a given address or with a given topic, before fetching the receipts.

The bloom filter can produce false positives but never false negatives: if it says "no", the block definitely has no matching logs, so a client can skip it entirely.

What logs cannot do

Two properties surprise people.

Contracts cannot read logs. Logs are write-only from the EVM's perspective. A contract cannot look up events emitted by another contract, or by itself. If a contract needs information later, it must store it in state. Logs exist purely for observers outside the chain.

Logs are not guaranteed to tell the truth about state. A log is whatever the contract's code chose to emit. A well-written token emits a Transfer event exactly when balances change. A buggy or malicious contract can emit events that do not match what actually happened — fake Transfer events from contracts imitating popular tokens are a common scam technique. The emitting address is the only thing that tells you which contract made the claim.

From raw logs to readable events

A raw log is a contract address, a list of 32-byte topics and a blob of data. Turning it into something readable is called decoding:

  1. Match the first topic against known event signatures to identify the event type.
  2. Use the contract's ABI — its published interface — to know which parameters are indexed and how the data field is encoded.
  3. Decode each topic and the data into named, typed values.

The result is a row like Transfer(from = 0xabc…, to = 0xdef…, value = 1,000,000). Analytics platforms decode logs at scale and store them as tables per event type. The decoded tables in the Wevr.ai live tables are exactly this: logs, decoded and organised by event.

A worked example

Take a USDC transfer. The transaction calls the USDC contract's transfer function. The contract updates two balances in its storage, then emits a log with:

  • topic 0: the hash of Transfer(address,address,uint256);
  • topic 1: the sender, padded to 32 bytes;
  • topic 2: the recipient, padded to 32 bytes;
  • data: the amount, as a 256-bit integer in USDC's smallest unit.

An explorer reading the receipt sees the log, recognises topic 0 as a Transfer, decodes the sender and recipient from topics 1 and 2, decodes the amount from data and divides by six decimals to show the human-readable value. The transaction's own "value" field is zero — the token movement exists only in the log.

Why it matters for analysis

Because analytics is built on logs, their properties shape what analysts can know:

  • Coverage depends on emission. If a contract does not emit an event for an action, that action is invisible to log-based analysis and must be reconstructed from traces or state.
  • Trust the emitter, not the event. Always check the contract address; never identify a token by the name in its events.
  • Watch for multiple events per action. Complex transactions emit many logs; counting them naively double-counts.

Querying decoded events directly is the most flexible way to work with them — the Wevr query engine exposes them as SQL tables.

The takeaway

Event logs are how contracts announce what they did: up to four searchable topics, a data blob, stored in receipts and summarised by a bloom filter in each header. Contracts cannot read them and they are only as honest as the code that emits them, but decoded at scale they are the foundation of nearly every on-chain metric. Learn to read a log, and you can read almost anything a contract does.

Index terms: event-logs · evm · receipts · decoding · abi

Next · § 2.1 · new chapter: ConsensusWhat Finality Actually Means (and Why Confirmations Aren't Settled) →