Ethereum Event Log Anatomy — Topics, Data & eth_getLogs
Smart contracts emit events that are recorded as logs on-chain. This reference explains the structure of a log — topics and data — and how eth_getLogs queries them efficiently.
Topics
topics[0] is the event signature hash — the keccak-256 hash of the canonical event signature such as Transfer(address,address,uint256). It identifies which event was emitted. Anonymous events omit this first topic. The remaining topics carry indexed parameters.
Indexed parameters
Up to three indexed parameters are stored in topics[1] through topics[3], each as a 32-byte word. Indexing a parameter makes it filterable but means only its 32-byte value is stored, so large types such as strings are stored as a hash rather than the original value.
The data field
Non-indexed parameters are ABI-encoded and concatenated in the data field. To read them you decode data according to the event's ABI. Indexed values live in topics; non-indexed values live in data — a decoder needs the ABI to reassemble the full event.
Filtering with eth_getLogs
eth_getLogs takes a filter with fromBlock and toBlock, one or more contract addresses, and a topics array. A null in a topic position matches anything; a value matches exactly; an array in a position matches any of several values (an OR). Filtering by topics[0] selects an event type, and by later topics selects specific indexed values such as a sender address.
Preguntas frecuentes
What is stored in topics[0]?
topics[0] holds the keccak-256 hash of the event's canonical signature, for example the hash of Transfer(address,address,uint256). It lets you identify and filter by event type. Anonymous events omit this topic.
Why can I only filter on some event parameters?
Only indexed parameters are placed in topics, and there can be at most three of them. eth_getLogs filters on topics, so non-indexed parameters — which live ABI-encoded in the data field — cannot be filtered directly and must be decoded after retrieval.
Herramientas relacionadas
Recarga, obtén tu clave y publica.
Autoservicio. Paga en cripto o con tarjeta. Medido por créditos: las primitivas pesadas cuestan más, las simples son baratas.
Obtener clave API