Skip to main content

eth_getLogs

Overview

The "eth_getLogs" method returns an array of all the logs matching the given filter object.

Request

curl --request POST \
--url https://ethereum-mainnet-geth-archive.node.coinapi.io \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'X-CoinAPI-Key: 73034021-THIS-IS-SAMPLE-KEY' \
--data '
{
"id": 1,
"jsonrpc": "2.0",
"method": "eth_getLogs",
"params": [
{
"address": [
"0xb59f67a8bff5d8cd03f6ac17265c550ed8f33907"
],
"fromBlock": "0x429d3b",
"toBlock": "latest",
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
"0x00000000000000000000000000b46c2526e227482e2ebb8f4c69e4674d262e75",
"0x00000000000000000000000054a2d42a40f51259dedd1978f6c118a0f0eff078"
]
}
]
}'

Request Parameters

A filter object containing the following:

  • address: (Optional) Contract address (20 bytes) or a list of addresses from which logs should originate.
  • fromBlock: (Optional, default is "'latest'") A hexadecimal block number, or the string 'latest', 'earliest' or 'pending'.
  • toBlock: (Optional, default is "'latest'") A hexadecimal block number, or the string 'latest', 'earliest' or 'pending'.
  • topics: (Optional) Array of 32 bytes DATA topics. Topics are order-dependent.
  • blockhash: (Optional) 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 the filter criteria, then neither fromBlock nor toBlock are allowed.

Response


{
"jsonrpc": "2.0",
"id": 1,
"result": [
{
"address": "0xb59f67a8bff5d8cd03f6ac17265c550ed8f33907",
"blockHash": "0x8243343df08b9751f5ca0c5f8c9c0460d8a9b6351066fae0acbd4d3e776de8bb",
"blockNumber": "0x429d3b",
"data": "0x000000000000000000000000000000000000000000000000000000012a05f200",
"logIndex": "0x56",
"removed": false,
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
"0x00000000000000000000000000b46c2526e227482e2ebb8f4c69e4674d262e75",
"0x00000000000000000000000054a2d42a40f51259dedd1978f6c118a0f0eff078"
],
"transactionHash": "0xab059a62e22e230fe0f56d8555340a29b2e9532360368f810595453f6fdd213b",
"transactionIndex": "0xac"
}
]
}

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

  • removed: (Boolean) true when the log was removed, due to a chain reorganization. false if it's a valid log.
  • logIndex: Hexadecimal of the log index position in the block. 'Null' when it is a pending log.
  • transactionIndex: Hexadecimal of the transactions index position from which the log was created. 'Null' when it is a pending log.
  • transactionHash: 32 bytes. Hash of the transactions from which this log was created. 'Null' when it is a pending log.
  • blockHash: 32 bytes. Hash of the block where this log was in. 'Null' when it is a pending log.
  • blockNumber: Block number where this log was in. 'Null' when it is a pending log.
  • address: 20 bytes. Address from which this log originated.
  • data: Contains one or more 32-bytes non-indexed arguments of the log.
  • topics: An array of 0 to 4 indexed log arguments, each 32 bytes.

Constraints

To ensure efficient use of resources, 'eth_getLogs' requests are subject to the following constraints:

  • A maximum of 5,000 parameters in a single request.
  • A maximum of 10,000 results can be returned by a single query.
  • Query duration must not exceed 10 seconds.

If a query returns too many results or exceeds the max query duration, one of the following errors is returned:

{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32005,
"message": "query returned more than 10000 results"
}
}

or

{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32005,
"message": "query timeout exceeded"
}
}

If this happens:

  • Limit your query to a smaller number of blocks using fromBlock and toBlock.
  • If querying for commonly used topics, consider limiting to a single smart contract address.