eth_getlogs

Base RPC

How to use it

// yarn add @tatumio/tatum

import { TatumSDK, Base, Network } from '@tatumio/tatum'

const tatum = await TatumSDK.init<Base>({ network: Network.BASE })

const logs = await tatum.rpc.getLogs({
  address: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
})

await tatum.destroy() // Destroy Tatum SDK - needed for stopping background jobs

Overview

The eth_getLogs method is an method that allows developers to query logs generated by the network, specifically event logs emitted by smart contracts. These logs are an essential part of the ecosystem as they provide a way for developers to monitor contract events and track contract state changes.

This method is particularly useful when building decentralized applications (dApps) that rely on events emitted by smart contracts, as it enables developers to retrieve logs based on specific filter criteria. By using eth_getLogs, developers can efficiently track and react to events happening on the blockchain.

Parameters

The eth_getLogs method takes a single input parameter: an object containing the filter criteria. The filter object can have the following fields:

  • fromBlock: (optional) The starting block number for the search. Can be a block number or one of the following strings: "earliest", "latest", or "pending".
    • Example: "fromBlock": "0x1"
  • toBlock: (optional) The ending block number for the search. Can be a block number or one of the following strings: "earliest", "latest", or "pending".
    • Example: "toBlock": "0x2"
  • address: (optional) The address or list of addresses of the contracts to filter logs from. Can be a single address or an array of addresses.
    • Example: "address": "0x88b17001c733f3834ee2d3a6da19c1e105359160"
  • topics: (optional) An array of up to four 32-byte topics. Topics are order-dependent, and each topic can be an array of topic hashes or null.
    • Example: "topics": ["0x123..."]
  • blockhash: (optional) The block hash to filter logs from. If provided, fromBlock and toBlock are ignored.
    • Example: "blockhash": "0xc6ef9..."

In addition to the above fields, the transactions field in the filter object can be specified to include full transaction details instead of just transaction hashes. This is useful when you need more information about the transactions in which the events were emitted.

Return Object

The eth_getLogs method returns an array of log objects. Each log object contains the following fields:

  • removed: A boolean indicating whether the log was removed due to a chain reorganization.
    • Example: "removed": false
  • logIndex: The log index position in the block.
    • Example: "logIndex": "0x1"
  • transactionIndex: The transaction index position in the block.
    • Example: "transactionIndex": "0x0"
  • transactionHash: The hash of the transaction that emitted the log.
    • Example: "transactionHash": "0x88eef..."
  • blockHash: The hash of the block containing the log.
    • Example: "blockHash": "0xc6ef9..."
  • blockNumber: The block number containing the log.
    • Example: "blockNumber": "0x1"
  • address: The address of the contract that emitted the log.
    • Example: "address": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
  • data: The data associated with the log.
    • Example: "data":"0x0000000000000000000000000000000000000000000000000000000000000020"
  • topics: An array of topics (order-dependent) associated with the log.
    • Example: "topics": ["0x123..."]

Response

{
  "jsonrpc": "2.0",
  "id": 74,
  "result": [
    {
      "address": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
      "topics": [
        "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
        "0x000000000000000000000000b72b27daf51d83b238c43f7d7ce6b461a774249b",
        "0x000000000000000000000000d7cabef2c1fd77a31c5ba97c724b82d3e25fc83c"
      ],
      "data": "0x000000000000000000000000000000000000000000000000000000017d784000",
      "blockNumber": "0xb2ee78",
      "transactionHash": "0x5247ee062df01daa659443b83a441fb6cccf1456672933f1da070908d08453c3",
      "transactionIndex": "0x4",
      "blockHash": "0x3d96d5e87dd68192b3b32f6badf50d53ee8347c278cd95a8b56e808b0fe9fbb8",
      "logIndex": "0xa",
      "removed": false
    },
    {
      "address": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
      "topics": [
        "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
        "0x000000000000000000000000d7cabef2c1fd77a31c5ba97c724b82d3e25fc83c",
        "0x0000000000000000000000006cdcb1c4a4d1c3c6d054b27ac5b77e89eafb971d"
      ],
      "data": "0x000000000000000000000000000000000000000000000000000000017d784000",
      "blockNumber": "0xb2ee78",
      "transactionHash": "0x5247ee062df01daa659443b83a441fb6cccf1456672933f1da070908d08453c3",
      "transactionIndex": "0x4",
      "blockHash": "0x3d96d5e87dd68192b3b32f6badf50d53ee8347c278cd95a8b56e808b0fe9fbb8",
      "logIndex": "0xd",
      "removed": false
    }
  ]
}