Indexing Event Logs
Event logs are emitted by smart contracts during transaction execution. TheaddLog() method allows you to subscribe to specific event logs from EVM-compatible blockchains.
addLog(options)
Subscribe to event logs emitted by some or all contracts in the network.
Options structure
Data request parameters
address- Set of contract addresses emitting the logs. Omit to subscribe to events from all contracts in the network.topicN- Set of values for topic0 through topic3. Topics are indexed event parameters.range- Range of blocks to consider (e.g.,{from: 1000000, to: 2000000}).
Related data retrieval
-
transaction = true- Retrieve all parent transactions and add them to thetransactionsiterable within the block data. Also exposes them via the.transactionfield of each log item. -
transactionLogs = true- Retrieve all “sibling” logs (logs emitted by transactions that emitted at least one matching log). Exposed through the regularlogsblock data iterable and via.transaction.logsfor matching logs. -
transactionTraces = true- Retrieve execution traces for all transactions that emitted at least one matching log. Exposed through the regulartracesblock data iterable and via.transaction.traces.
Logs can also be requested by
addTransaction() and
addTrace() as related data.Field selection
Use thesetFields() method to select exactly which data fields to retrieve for each log. See the Field selection page for details.
Examples
Example 1: Fetch Gravatar events with parent transactions
FetchNewGravatar and UpdateGravatar event logs from a specific contract, including log topics, data, and parent transaction inputs:
Example 2: Filter by indexed address parameter
Fetch everyTransfer(address,address,uint256) event where topic2 (destination address) matches vitalik.eth (0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045):
Address padding for topics: The address in
topic2 must be 66 characters long (including the 0x prefix) because Squid SDK expects Bytes32[] values. Pad shorter addresses with leading zeros:
