eth_getLogs

Ethereum RPC

Overview

The eth_getLogs method is an Ethereum JSON-RPC method that allows developers to query logs generated by the Ethereum network, specifically event logs emitted by smart contracts. These logs are an essential part of the Ethereum 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 Ethereum 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": "0x1"
  • 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": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"
  • 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.

Returns

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

NameDescriptionExample
removedA boolean indicating whether the log was removed due to a chain reorganization."removed": false
logIndexThe log index position in the block."logIndex": "0x1"
transactionIndexThe transaction index position in the block."transactionIndex": "0x0"
transactionHashThe hash of the transaction that emitted the log."transactionHash": "0x88eef..."
blockHashThe hash of the block containing the log."blockHash": "0xc6ef9..."
blockNumberThe block number containing the log."blockNumber": "0x1"
addressThe address of the contract that emitted the log."address": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"v
dataThe data associated with the log."data":"0x0000000000000000000000000000000000000000000000000000000000000020"
topicsAn array of topics (order-dependent) associated with the log."topics": ["0x123..."]

Request

curl --location 'https://api.tatum.io/v3/blockchain/node/ethereum-mainnet/' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {API_KEY}' \
--data '{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "eth_getLogs",
  "params": [
    {
      "fromBlock": "0x1",
      "toBlock": "0x2",
      "address": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
      "topics": ["0x123..."]
    }
  ]
}'
// yarn add @tatumio/tatum

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

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

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

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