eth_getLogs

How to use it

// yarn add @tatumio/tatum

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

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

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

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

Overview

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

This method is particularly useful when building decentralised 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 Polygon blockchain.

Parameters

The eth_getLogs the 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. It 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. It 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. It can be a single address or an array of addresses.

    • Example: "address": "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174"

  • 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 the 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 the 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": "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174"

  • data: The data associated with the log.

    • Example: "data":"0x0000000000000000000000000000000000000000000000000000000000000020"

  • topics: An array of topics (order-dependent) associated with the log.

    • Example: "topics": ["0x123..."]

JSON-RPC Examples

Request

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "eth_getLogs",
  "params": [
    {
      "fromBlock": "0x1",