eth getLogs.md
eth_getLogs RPC Method
Returns an array of all logs matching a given filter object.
Parameters
- object (object (optional)): The transaction call object which contains the following fields
- fromBlock (string (optional)): The block number as a string in hexadecimal format or tags. The supported tag values include earliest for the earliest/genesis block, latest for the latest mined block, pending for the pending state/transactions, safe for the most recent secure block, and finalized for the most recent secure block accepted by more than 2/3 of validators
- toBlock (string (optional)): The block number as a string in hexadecimal format or tags. The supported tag values include earliest for the earliest/genesis block, latest for the latest mined block, pending for the pending state/transactions, safe for the most recent secure block, and finalized for the most recent secure block accepted by more than 2/3 of validators
- address (string (optional)): The contract address or a list of addresses from which logs should originate
- topics (array (optional)): An array of DATA topics and also, the topics are order-dependent
- blockHash (string (optional)): With the addition of EIP-234, blockHash is a new filter option that restricts the logs returned to the block number referenced in the blockHash. Using the blockHash field is equivalent to setting the fromBlock and toBlock to the block number the blockHash references. If blockHash is present in the filter criteria, neither fromBlock nor toBlock is allowed
Returns
- result (array): An array of log objects, or an empty array if nothing has changed since last poll
- address (string): The address from which this log originated
- topics (array): An array of (0 to 4) 32 Bytes DATA 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)
- data (string): It contains one or more 32 Bytes non-indexed arguments of the log
- blockHash (string): The hash of the block where this log was in. Null when it's a pending log
- blockNumber (string): The block number where this log was in. null when its pending
- transactionHash (string): The hash of the transaction from which this log was created from. null if the log is pending
- transactionIndex (string): The integer of the transaction's index position that the log was created from. Null when it's a pending log
- logIndex (string): The integer of the log index position in the block. Null when it's a pending log
- transactionLogIndex (string): The index of the log within the transaction, detailing the order in which events occurred
- logType (string): Describes the type of log
- removed (boolean): It is true if log was removed, due to a chain reorganization and false if it's a valid log
- blockTimestamp (string): The timestamp of the block in which the log was included encoded in hexadecimal format
Code Examples
CURL
curl -X POST "https://docs-demo.robinhood-mainnet.quiknode.pro/" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_getLogs",
"params": [
{
"address": "0x3a81867dd8e264a6eb63dec701e531b5537d5969"
}
],
"id": 1
}'
ETHERS
import { ethers } from "ethers";
async function main() {
const provider = new ethers.JsonRpcProvider("https://docs-demo.robinhood-mainnet.quiknode.pro/");
const response = await provider.send("eth_getLogs", [
{
"address": "0x3a81867dd8e264a6eb63dec701e531b5537d5969"
}
]);
console.log(response);
}
main();
ETH_RB
require 'eth'
client = Eth::Client.create 'https://docs-demo.robinhood-mainnet.quiknode.pro/'
payload = {
"jsonrpc": "2.0",
"method": "eth_getLogs",
"params": [
{
"address": "0x3a81867dd8e264a6eb63dec701e531b5537d5969"
}
],
"id": "1"
}
response = client.send(payload.to_json)
puts response
WEB3PY
from web3 import Web3, HTTPProvider
w3 = Web3(HTTPProvider('https://docs-demo.robinhood-mainnet.quiknode.pro/'))
response = w3.provider.make_request("eth_getLogs", [{"address":"0x3a81867dd8e264a6eb63dec701e531b5537d5969"}])
print(response)
VIEM
import { createPublicClient, http } from 'viem'
async function main() {
const client = createPublicClient({
transport: http('https://docs-demo.robinhood-mainnet.quiknode.pro/')
})
const result = await client.request({
method: 'eth_getLogs',
params: [
{
"address": "0x3a81867dd8e264a6eb63dec701e531b5537d5969"
}
]
})
console.log(result)
}
main()
QNSDK
import { Core } from '@quicknode/sdk'
const core = new Core({
endpointUrl: "https://docs-demo.robinhood-mainnet.quiknode.pro/",
})
core.client
.request({
method: 'eth_getLogs',
params: [{"address":"0x3a81867dd8e264a6eb63dec701e531b5537d5969"}]
})
.then(res => console.log(res))
JAVASCRIPT
const body = {
jsonrpc: '2.0',
method: 'eth_getLogs',
params: [{"address":"0x3a81867dd8e264a6eb63dec701e531b5537d5969"}],
id: 1
}
async function main() {
const response = await fetch('https://docs-demo.robinhood-mainnet.quiknode.pro/', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(body)
})
const data = await response.json()
console.log(data)
}
main()
PYTHON
import requests
import json
url = "https://docs-demo.robinhood-mainnet.quiknode.pro/"
payload = json.dumps({
"jsonrpc": "2.0",
"method": "eth_getLogs",
"params": [
{
"address": "0x3a81867dd8e264a6eb63dec701e531b5537d5969"
}
],
"id": 1
})
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
RUBY
require "uri"
require "json"
require "net/http"
uri = URI("https://docs-demo.robinhood-mainnet.quiknode.pro/")
payload = {
jsonrpc: "2.0",
id: 1,
method: "eth_getLogs",
params: [{"address":"0x3a81867dd8e264a6eb63dec701e531b5537d5969"}]
}
request = Net::HTTP::Post.new(uri)
request["Content-Type"] = "application/json"
request.body = JSON.generate(payload)
response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
http.request(request)
end
puts response.body
STATIC-RESPONSE
{
"jsonrpc": "2.0",
"id": 1,
"result": []
}