eth_getLogs

Returns an array of all logs matching a given filter object.

Parameters

  1. Filter Object

    • blockhash [optional] With the addition of EIP-234, blockHash restricts the logs returned to the single block with the 32-byte hash blockHash. Using blockHash is equivalent to fromBlock = toBlock = the block number with hash blockHash. If blockHash is present in in the filter criteria, then neither fromBlock nor toBlock are allowed.

    • topics [optional] Array of 32 Bytes DATA topics. Topics are order-dependent.

    • fromBlock [optional, default: latest] a hexadecimal block number, or the string latest, earliest or pending, See the default block parameter.

    • toBlock [optional, default: latest] a hexadecimal block number, or the string latest, earliest or pending, See the default block parameter.

    • address [optional] a string representing the address (20 bytes) to check for balance

Request

curl https://eth-mainnet.solarpath.io/v1/YOUR-API-KEY \
    -X POST \
    -H "Content-Type: application/json" \
    -d '{"jsonrpc": "2.0", "id": 1, "method": "eth_getLogs", "params": [{"blockhash": "0xe429155011f1e8bcd46802dd261c6855e5fe3ed4d1622d047920e40dcb0e0da8","topics": ["0x23919512b2162ddc59b67a65e3b03c419d4105366f7d4a632f5d3c3bee9b1cff"]}]}'

Response

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": [
    {
      // address from which this log originated.
      "address": "0x209c4784ab1e8183cf58ca33cb740efbf3fc18ef",
      // block Hash
      "blockHash": "0xe429155011f1e8bcd46802dd261c6855e5fe3ed4d1622d047920e40dcb0e0da8",
      // block number
      "blockNumber": "0x658a13",
      "data": "0x00000000000000000000000032be343b94f860124dc4fee278fdcbd38c102d88",
      // hexadecimal of the log index position in the block. null when its pending log.
      "logIndex": "0x0",
      // true when the log was removed, due to a chain reorganization. false if it's a valid log.
      "removed": false,
      // Array of 0 to 4 32 Bytes of indexed log arguments. 
      // In solidity: The first topic is the hash of the signature of the event (e.g. Deposit(address,bytes32,uint256)), except you declared the event with the anonymous specifier.
      "topics": [
          "0x23919512b2162ddc59b67a65e3b03c419d4105366f7d4a632f5d3c3bee9b1cff"
      ],
      // hash of the transactions this log was created from. null when its pending log.
      "transactionHash": "0x420ac75c166f74a1a3af051a0c0cba9dded1ee3378d5770097877dddf29590df",
      // hexadecimal of the transactions index position log was created from. null when its pending log.
      "transactionIndex": "0xf"
    }
  ]
}

In order to prevent the query from consuming too much resources, the eth_getLogs query single result set is limited to 10,000, and the query duration should not exceed 10s.

If the above abnormal situation occurs, it is recommended to do the following:

  • Use fromBlock and toBlock to limit your query to a smaller range of blocks.

  • If querying for commonly used topics, consider limiting to a single Smart Contract address as well.

  • For frequent pulls, the best practice is to use the Event Hook provided by SolarPath to receive logs.

Last updated