🐹
ChainRPC
  • Welcome to Chain-RPC Docs
  • Getting started
  • Networks
    • Ethereum
      • Concepts
        • Transaction types
        • Filters and subscriptions
      • How to
        • Authenticate requests
        • Make requests
        • Make batch requests
        • Choose a network
        • Subscribe to events
        • Interact with ERC-20 tokens
        • Add a network add-on
        • Secure a project
          • API key
          • API key secret
          • JWTs
          • Rate limits
          • Allowlists
        • Avoid rate limiting
      • JSON-RPC methods
        • eth_accounts
        • eth_blockNumber
        • eth_call
        • eth_chainId
        • eth_coinbase
        • eth_estimateGas
        • eth_feeHistory
        • eth_getBalance
        • eth_gasPrice
        • eth_getBlockByHash
        • eth_getBlockByNumber
        • eth_getBlockTransactionCountByHash
        • eth_getBlockTransactionCountByNumber
        • eth_getCode
        • eth_getLogs
        • eth_getStorageAt
        • eth_getTransactionByBlockHashAndIndex
        • eth_getTransactionByBlockNumberAndIndex
        • eth_getTransactionByHash
        • eth_getTransactionCount
        • eth_getTransactionReceipt
        • eth_getUncleByBlockHashAndIndex
        • eth_getUncleByBlockNumberAndIndex
        • eth_getUncleCountByBlockHash
        • eth_getUncleCountByBlockNumber
        • eth_getWork
        • eth_mining
        • eth_hashrate
        • eth_protocolVersion
        • eth_sendRawTransaction
        • eth_sendTransaction
        • eth_sign
        • eth_submitWork
        • eth_syncing
        • net_listening
        • net_peerCount
        • net_version
        • web3_clientVersion
        • Filter methods
          • eth_newFilter
          • eth_newBlockFilter
          • eth_newPendingTransactionFilter
          • eth_getFilterLogs
          • eth_getFilterChanges
          • eth_uninstallFilter
        • Subscription methods
          • eth_subscribe
          • eth_unsubscribe
    • Arbitrum
      • How to
        • Authenticate requests
        • Make requests
        • Choose a network
        • Secure a project
        • Get testnet ETH
      • JSON-RPC API methods
    • Aurora
      • How to
      • JSON-RPC API methods
    • Avalanche (C-Chain)
      • How to
      • JSON-RPC API methods
    • BNB Chain
      • How to
      • JSON-RPC API methods
    • Celo
      • How to
      • JSON-RPC API methods
    • Cube
      • How to
      • JSON-RPC API methods
    • Fantom
      • How to
      • JSON-RPC API methods
    • Gnosis
      • How to
      • JSON-RPC API methods
    • Heco
      • How to
      • JSON-RPC API methods
    • Klaytn
      • How to
      • JSON-RPC API methods
    • Optimism
      • How to
      • JSON-RPC API methods
    • OEC Chain
      • How to
      • JSON-RPC API methods
    • Polygon PoS
      • How to
      • JSON-RPC API methods
  • Custom APIs
    • Wellat SDK
    • DeX SDK
    • NFT SDK
Powered by GitBook
On this page
  • REQUEST
  • RESPONSE
  1. Networks
  2. Ethereum
  3. JSON-RPC methods

eth_getLogs

Returns an array of all logs matching a given filter object.

REQUEST

POST https://<network>.chainrpc.io/v3/YOUR-API-KEY

HEADERS

Content-Type: application/json

REQUEST PARAMS

  • FILTER OBJECT

    • address [optional] - a string representing the address (20 bytes) to check for balance

    • fromBlock [optional, default is "latest"] - hexadecimal block number, or the string "latest", "earliest" or "pending"

    • toBlock [optional, default is "latest"] - hexadecimal block number, or the string "latest", "earliest" or "pending"

    • topics[optional] - Array of 32 Bytes DATA topics. Topics are order-dependent.

    • blockhash:[optional] With the addition of EIP-234, blockHash restricts the logs returned to the single block with the 32-byte hash blockHash. Using blockHash is equivalent to fromBlock = toBlock = the block number with hash blockHash. If blockHash is present in in the filter criteria, then neither fromBlock nor toBlock are allowed.

EXAMPLE

## JSON-RPC over HTTPS POST
## Replace YOUR-API-KEY with an API key from your chainRPC Dashboard
## You can also replace mainnet with a different supported network
curl https://eth.chainrpc.io/v3/YOUR-API-KEY \
    -X POST \
    -H "Content-Type: application/json" \
    -d '{"jsonrpc":"2.0","method":"eth_getLogs","params":[{"blockHash": "0x7c5a35e9cb3e8ae0e221ab470abae9d446c3a5626ce6689fc777dcffcab52c70", "topics":["0x241ea03ca20251805084d27d4440371c34a0b85ff108f6bb5611248f73818b80"]}],"id":1}'

## JSON-RPC over WSS
## Replace YOUR-API-KEY with an API key from your chainRPC Dashboard
## You can also replace mainnet with a different supported network
wscat -c wss://eth.chainrpc.io/v3/YOUR-API-KEY
>{"jsonrpc":"2.0","method":"eth_getLogs","params":[{"blockHash": "0x7c5a35e9cb3e8ae0e221ab470abae9d446c3a5626ce6689fc777dcffcab52c70", "topics":["0x241ea03ca20251805084d27d4440371c34a0b85ff108f6bb5611248f73818b80"]}],"id":1}

RESPONSE

RESULT FIELDS

  • LOG OBJECTS - An array of log objects, or an empty array if nothing has changed since last poll.

    • logs are objects with following params:

      • removed: 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 its pending log.

      • transactionIndex: hexadecimal of the transactions index position log was created from. null when its pending log.

      • transactionHash: 32 Bytes - hash of the transactions this log was created from. null when its pending log.

      • blockHash: 32 Bytes - hash of the block where this log was in. null when its pending. null when its pending log.

      • blockNumber: the block number where this log was in. null when its pending. null when its 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: Array of 0 to 4 32 Bytes of indexed log arguments. (In solidity: The first topic is the hash of the signature of the event (e.g. Deposit(address,bytes32,uint256)), except you declared the event with the anonymous specifier.)

BODY

{
    "jsonrpc": "2.0",
    "id": 1,
    "result": [
        {
            "address": "0x1a94fce7ef36bc90959e206ba569a12afbc91ca1",
            "blockHash": "0x7c5a35e9cb3e8ae0e221ab470abae9d446c3a5626ce6689fc777dcffcab52c70",
            "blockNumber": "0x5c29fb",
            "data": "0x0000000000000000000000003e3310720058c51f0de456e273c626cdd35065700000000000000000000000000000000000000000000000000000000000003185000000000000000000000000000000000000000000000000000000000000318200000000000000000000000000000000000000000000000000000000005c2a23",
            "logIndex": "0x1d",
            "removed": false,
            "topics": [
                "0x241ea03ca20251805084d27d4440371c34a0b85ff108f6bb5611248f73818b80"
            ],
            "transactionHash": "0x3dc91b98249fa9f2c5c37486a2427a3a7825be240c1c84961dfb3063d9c04d50",
            "transactionIndex": "0x1d"
        },
        {
            "address": "0x06012c8cf97bead5deae237070f9587f8e7a266d",
            "blockHash": "0x7c5a35e9cb3e8ae0e221ab470abae9d446c3a5626ce6689fc777dcffcab52c70",
            "blockNumber": "0x5c29fb",
            "data": "0x00000000000000000000000077ea137625739598666ded665953d26b3d8e374400000000000000000000000000000000000000000000000000000000000749ff00000000000000000000000000000000000000000000000000000000000a749d00000000000000000000000000000000000000000000000000000000005c2a0f",
            "logIndex": "0x57",
            "removed": false,
            "topics": [
                "0x241ea03ca20251805084d27d4440371c34a0b85ff108f6bb5611248f73818b80"
            ],
            "transactionHash": "0x788b1442414cb9c9a36dba2abe250763161a6f6395788a2e808f1b34e92beec1",
            "transactionIndex": "0x54"
        }
    ]
}

LIMITATIONS

To prevent queries from consuming too many resources, eth_getLogs requests are currently limited by two constraints:

  • A max 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"
  }
}
{
  "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 as well.

Previouseth_getCodeNexteth_getStorageAt

Last updated 2 years ago