eth_getLogs - Gravity

This method returns an array of all logs matching a given filter object in a single call. It is the primary method for querying event logs from smart contracts, essential for tracking token transfers, DEX swaps, and other on-chain events.

Parameters

ParameterTypeRequiredDescription
filterObjectobjectYesFilter criteria object

Filter Object

FieldTypeRequiredDescription
fromBlockstringNoStart block in hex, or "latest"
toBlockstringNoEnd block in hex, or "latest"
addressstring | arrayNoContract address(es) to match
topicsarrayNoOrdered topic filters (null matches any position)
blockHashstringNoRestrict to a single block by hash (mutually exclusive with from/toBlock)

Request

bashcurl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "eth_getLogs",
    "params": [{ "fromBlock": "0x14b8a10", "toBlock": "0x14b8b10", "address": "0x6a004c1d7e3a6084b5c9d0e1f2a3b4c5d6e7f809", "topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"] }],
    "id": "getblock.io"
}'

example.js

javascriptconst axios = require('axios');

const response = await axios.post('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/', {
    jsonrpc: '2.0',
    method: 'eth_getLogs',
    params: [{ fromBlock: '0x14b8a10', toBlock: '0x14b8b10', address: '0x6a004c1d7e3a6084b5c9d0e1f2a3b4c5d6e7f809', topics: ['0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'] }],
    id: 'getblock.io'
}, {
    headers: { 'Content-Type': 'application/json' }
});

console.log(response.data.result);

example.py

pythonimport requests

response = requests.post(
    'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/',
    headers={'Content-Type': 'application/json'},
    json={
        'jsonrpc': '2.0',
        'method': 'eth_getLogs',
        'params': [{ 'fromBlock': '0x14b8a10', 'toBlock': '0x14b8b10', 'address': '0x6a004c1d7e3a6084b5c9d0e1f2a3b4c5d6e7f809', 'topics': ['0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'] }],
        'id': 'getblock.io'
    }
)

print(response.json())

example.rs

rustuse reqwest::Client;
use serde_json::{json, Value};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();

    let response = client
        .post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
        .header("Content-Type", "application/json")
        .json(&json!({
            "jsonrpc": "2.0",
            "method": "eth_getLogs",
            "params": [{ "fromBlock": "0x14b8a10", "toBlock": "0x14b8b10", "address": "0x6a004c1d7e3a6084b5c9d0e1f2a3b4c5d6e7f809", "topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"] }],
            "id": "getblock.io"
        }))
        .send()
        .await?
        .json::<Value>()
        .await?;

    println!("Result: {}", response["result"]);
    Ok(())
}

Response

json{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": [
        {
            "address": "0x6a004c1d7e3a6084b5c9d0e1f2a3b4c5d6e7f809",
            "blockNumber": "0x14b8a10",
            "transactionHash": "0x3c8a1f5b2d9e4076c1a8b3d5e7f9021436587a9cbdef012345678abcdef901234",
            "logIndex": "0x0",
            "topics": [
                "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
            ],
            "data": "0x"
        }
    ]
}

Response Parameters

ParameterTypeDescription
jsonrpcstringJSON-RPC protocol version ("2.0")
idstringRequest identifier matching the request
resultarrayArray of log objects matching the filter

Use Cases

  • Token Transfers: Track ERC-20 Transfer events by topic and address
  • DEX Activity: Index swap and liquidity events from AMM pools
  • Indexing: Backfill contract events over a block range
  • Analytics: Aggregate on-chain events for dashboards

Error Handling

Error CodeMessageDescription
-32602Invalid paramsMalformed filter object or block range
-32005Limit exceededThe requested block range or result set is too large
-32603Internal errorThe node failed to assemble the logs

Web3 Integration

ethers-example.js

javascriptimport { ethers } from 'ethers';

const provider = new ethers.JsonRpcProvider('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/');

const logs = await provider.getLogs({ address: '0x6a004c1d7e3a6084b5c9d0e1f2a3b4c5d6e7f809', topics: ['0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'], fromBlock: 21727760 });

viem-example.js

javascriptimport { createPublicClient, http } from 'viem';

const client = createPublicClient({
  transport: http('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/')
});

const logs = await client.getLogs({ address: '0x6a004c1d7e3a6084b5c9d0e1f2a3b4c5d6e7f809', fromBlock: 21727760n });