Logs API
Get Logs

Get Logs

Overview

The Get Logs endpoint obtains data on interactions with smart contracts by analyzing their log events. At least one of the following parameters must be specified: topic_0, topic_1, topic_2, topic_3, contract, or origin. The range should be defined by either block_number, timestamp, or block_hash. Logs can be decoded and converted into a human-readable format when a smart contract's ABI is provided.

📘️

Multiple values can be set for these parameters: topic_0, topic_1, topic_2, topic_3, and contract, with a maximum of five items each.

Use Cases

Several possible combinations of parameters should be considered, where origin refers to the address of an EOA wallet, contract is a smart contract's address, topic 0 represents the event signature hash, and topics 1-3 correspond to three indexed arguments as defined in the Solidity code of a particular smart contract. To retrieve specific details about logs and their events, follow the guidelines below.

  1. For logs generated by a particular contract triggered by an EOA wallet, specify both contract and origin.

  2. For logs generated by a particular contract and filtered by event signature hash, specify both the contract and topic 0.

  3. For logs generated by multiple contracts triggered by an EOA wallet and filtered by event signature hash, specify both origin and topic 0.

  4. For logs generated by a particular contract triggered by an EOA wallet and filtered by event signature hash, specify contract, origin, and topic 0.

📘️

When using decoding, the output will include a decoded object with the event name, its parameters and values.

Querying via Postman

If you prefer querying via Postman, the description of PARSIQ Endpoints for Get Logs (opens in a new tab) and Get Decoded Logs (opens in a new tab) might come in handy. There you will find examples and responses for good and bad requests as well as parameter definitions and their example values.

Usage

In this example, we receive all log events on the contract 0xBd3531dA5CF5857e7CfAA92426877b022e612cf8 with the given topics for the last 10,000 blocks. The query is also filtered by the origin address 0x00401092edc6b62d250df362c640a618a8c1052a and the LOG4 opcode.

import * as Parsiq from '@parsiq/parsiq.js';
import {OpCode} from '@parsiq/parsiq.js';
 
const client = Parsiq.createClient(process.env.API_KEY, Parsiq.ChainId.ETH_MAINNET);
 
const logs = client.logs.getByBlockRange(
    -10000, 'latest',
    {
      contract: ['0xBd3531dA5CF5857e7CfAA92426877b022e612cf8'],
      topic_0: ['0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925'],
      topic_1: ['0x00000000000000000000000000401092edc6b62d250df362c640a618a8c1052a'],
      topic_2: ['0x0000000000000000000000000000000000000000000000000000000000000000'],
      topic_3: ['0x0000000000000000000000000000000000000000000000000000000000000833'],
      origin: '0x00401092edc6b62d250df362c640a618a8c1052a',
      op_code: OpCode.LOG4
    },
    {
      limit: 1
    }
);
 
for await (const event of logs) {
    console.log(event);
}

Output:

{
  id: '0000000001256fd0-006a-00000003',
  topic_0: '0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925',
  topic_1: '0x00000000000000000000000000401092edc6b62d250df362c640a618a8c1052a',
  topic_2: '0x0000000000000000000000000000000000000000000000000000000000000000',
  topic_3: '0x0000000000000000000000000000000000000000000000000000000000000833',
  log_data: '0x',
  tx_hash: '0x13b892934bdd9725d39a7f92f257c248a9fe8dceead369ed1e7be0555ac0943c',
  block_hash: '0x3a913919ce04cdcc1e5d6d57f562c08e782a77b2e2b0aee7e3e7c83d02a250ef',
  block_number: 19230672,
  timestamp: 1707967967,
  op_code: 'LOG4',
  origin: '0x00401092edc6b62d250df362c640a618a8c1052a',
  contract: '0xbd3531da5cf5857e7cfaa92426877b022e612cf8'
}

Parameters

Path params
chainId
string
REQUIRED
version
string
REQUIRED
Query params
block_number_start
number
REQUIRED
block_number_end
string
number
REQUIRED
origin
string
OR
contract
array of strings
OR
topic_0
array of strings
OR
topic_1
array of strings
OR
topic_2
array of strings
OR
topic_3
array of strings
op_code
string
offset
string
limit
number
estimate_cu
boolean