Skip to main content
V2 gateway requests require an API key. Set SQD_API_KEY in .env before running gateway-based examples, or pass apiKey: process.env.SQD_API_KEY in GatewaySettings.

addLog(options)

Get event logs emitted by some or all contracts in the network. options has the following structure:
Data requests:
  • address: the set of addresses of contracts emitting the logs. Omit to subscribe to events from all contracts in the network.
  • topicN: the set of values of topicN.
  • range: the range of blocks to consider.
Related data retrieval:
  • transaction = true: the processor will retrieve all parent transactions and add them to the transactions iterable within the block data. Additionally it will expose them via the .transaction field of each log item.
  • transactionLogs = true: the processor will retrieve all “sibling” logs, that is, all logs emitted by transactions that emitted at least one matching log. The logs will be exposed through the regular logs block data iterable and via .transaction.logs for matching logs.
  • transactionTraces = true: the processor will retrieve the traces for all transactions that emitted at least one matching log. The traces will be exposed through the regular traces block data iterable and via .transaction.traces.
  • transactionStateDiffs = true: the processor will retrieve state diffs for all transactions that emitted at least one matching log. They are exposed through the regular stateDiffs iterable and via .transaction.stateDiffs.
All string filters are normalized to lowercase by the processor. Note that logs can also be requested by addTransaction() and addTrace() method as related data. Selection of the exact data to be retrieved for each log and its optional parent transaction is done with the setFields() method documented on the Field selection page. Some examples are available below.

Examples

  1. Fetch NewGravatar(uint256,address,string,string) and UpdateGravatar(uint256,address,string,string) event logs emitted by 0x2E645469f354BB4F5c8a05B3b30A929361cf77eC. For each log, fetch topic set, log data. Fetch parent transactions with their inputs.
Typescript ABI modules generated by squid-evm-typegen provide event signatures/topic0 values as constants, e.g.
  1. Fetch every Transfer(address,address,uint256) event on Ethereum mainnet where topic2 is set to the destination address (a common but non-standard practice) and the destination is vitalik.eth a.k.a. 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045. For each log, fetch transaction hash.
As you may observe, the address in the topic2 is a bit longer than usual (0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045, 42 chars). This is caused by the fact that Squid SDK expects Bytes32[]; therefore, the length has to be 66 chars long. The possible quick fix is to pad the original address with zeros and prepend 0x.