Try it Live
Run EventLog examples in the interactive playground
Conceptual Guide - For API reference and method documentation, see EventLog API.
Structure
An event log contains:- Address - Contract that emitted the log (20 bytes)
- Topics - Up to 4 indexed parameters (32 bytes each)
- Data - Non-indexed parameters (variable length)
- Metadata - Block number, transaction hash, log index
Topics and Indexed Parameters
Topics enable efficient log filtering via bloom filters. The first topic (topic0) is the event signature hash:- topic0 -
keccak256("Transfer(address,address,uint256)") - topic1 -
fromaddress (padded to 32 bytes) - topic2 -
toaddress (padded to 32 bytes) - data -
value(not indexed, in log data field)
Creating and Parsing Event Logs
- TypeScript
Event Signature Hashing
Event signatures are computed by hashing the canonical event declaration:Filtering Event Logs
Address Filtering
Topic Filtering
Complete Filter
Bloom Filters in Block Headers
Block headers contain a 2048-bit bloom filter enabling efficient log queries without scanning all transactions.How Bloom Filters Work
- For each log, hash the address and each topic
- Set 3 bits in the bloom filter per hash
- To query: check if all required bits are set
- False positives possible, false negatives impossible
ABI Decoding Integration
Event data requires ABI decoding for non-indexed parameters:Anonymous Events
Anonymous events omit the signature hash (topic0), allowing 4 indexed parameters instead of 3:- topic0 -
from(first indexed parameter, NOT signature) - topic1 -
to - topic2 -
tokenId - topic3 -
price - data - Empty (all parameters indexed)
Complete Example: ERC-20 Transfer Tracking
Chain Reorganizations
Logs can be marked asremoved: true when chain reorganizations invalidate their blocks:
Performance Considerations
Bloom Filter False Positives
Bloom filters enable fast queries but produce false positives (10-20% typical):Efficient Filtering
Resources
- Ethereum Yellow Paper - Section 4.3 (Transaction Receipt) and 4.3.1 (Log Objects)
- Solidity Events - Event declaration and emission
- eth_getLogs - JSON-RPC method for querying logs
- EIP-234 - Bloom filter specification
Next Steps
- Overview - Type definition and API reference
- matchesTopics - Topic filtering logic
- filterLogs - Batch log filtering
- BloomFilter - Bloom filter implementation

