Updated on 2024-11-14 GMT+08:00

eth_getLogs

Introduction

This API returns an array of all the logs matching the given filter object. It consumes 75 CUs.

Parameter Description

Parameter

Type

Description

address

String

(Optional) A 20-byte contract address or a list of addresses from which logs should originate.

fromBlock

String

(Optional) A hexadecimal block number, or the string (earliest, latest, or pending). Latest is set by default.

toBlock

String

(Optional) A hexadecimal block number, or the string (earliest, latest, or pending). Latest is set by default.

topics

String

(Optional) An array of 32-byte data topics. Topics are order-dependent.

blockhash

String

(Optional) It restricts the logs returned to the single block referenced in the 32-byte hash blockHash. Using blockHash is equivalent to setting fromBlock and toBlock to the block number referenced in the blockHash. If blockHash is present in in the filter criteria, then neither fromBlock nor toBlock are allowed.

Return Value

An array of log objects, or an empty array if nothing has changed since last poll. Log objects contain the following keys and their values:

  • removed: true when the log was removed due to a chain reorganization. false if it is a valid log.
  • logIndex: the hexadecimal of the log index position in the block. It is null for a pending log.
  • transactionIndex: the hexadecimal of the transactions index position from which the log created. It is null for a pending log.
  • transactionHash: 32 bytes. The hash of the transactions from which this log was created. It is null for a pending log.
  • blockHash: 32 bytes. The hash of the block where this log was in. It is null for a pending log.
  • blockNumber: the block number where this log was in. It is null for a pending log.
  • address: 20 bytes. The address from which this log originated.
  • data: It contains one or more 32-byte non-indexed arguments of the log.
  • topics: an array of 0 to 4 indexed log arguments, each 32 bytes. In Solidity, the first topic is the hash of the signature of the event (e.g. Deposit(address,bytes32,uint256)), except you declare the event with the anonymous specifier.

Request

curl https://your-http-endpoint/v1/<API-KEY> \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_getLogs","params":[{"blockHash": "0x7c5a35e9cb3e8ae0e221ab470abae9d446c3a5626ce6689fc777dcffcab52c70", "topics":["0x241ea03ca20251805084d27d4440371c34a0b85ff108f6bb5611248f73818b80"]}],"id":74}'