eth_newFilter - Ethereum

This method creates a log filter that matches events emitted by contracts based on address, topic, and block-range criteria. It returns a filter ID that subsequent eth_getFilterChanges or eth_getFilterLogs calls use to fetch matching logs. Filters are stateful — they persist on the node until explicitly uninstalled or expired.

Parameters

ParameterTypeRequiredDescription
filterobjectYesFilter criteria (see below)

Filter Object

FieldTypeRequiredDescription
fromBlockstringNoStarting block — hex number or latest, earliest, pending, finalized, safe. Defaults to latest
toBlockstringNoEnding block — hex number or tag. Defaults to latest
addressstring or array of stringNoContract address(es) to filter logs from
topicsarrayNoTopic filters — up to 4 topics; each can be a single value, array (OR), or null (any)

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_newFilter",
    "params": [
        {
            "fromBlock": "0x1720340",
            "toBlock": "latest",
            "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
            "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_newFilter',
    params: [
        {
            "fromBlock": "0x1720340",
            "toBlock": "latest",
            "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
            "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_newFilter',
        'params': [
        {
            "fromBlock": "0x1720340",
            "toBlock": "latest",
            "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
            "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_newFilter",
            "params": [
        {
            "fromBlock": "0x1720340",
            "toBlock": "latest",
            "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
            "topics": [
                "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
            ]
        }
    ],
            "id": "getblock.io"
        }))
        .send()
        .await?
        .json::<Value>()
        .await?;
    
    println!("Result: {}", response["result"]);
    Ok(())
}

Response

json{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": "0x16"
}

Response Parameters

ParameterTypeDescription
jsonrpcstringJSON-RPC protocol version ("2.0")
idstringRequest identifier matching the request
resultstringHex-encoded filter ID — pass to eth_getFilterChanges or eth_getFilterLogs

Use Cases

  • ERC-20 Transfer Monitoring: Filter for Transfer events emitted by a token contract to build a wallet activity feed
  • DEX Trade Indexing: Filter for Swap events on Uniswap V3 pools to feed an indexer
  • Governance Vote Tracking: Filter for governance events (VoteCast, ProposalCreated) across DAO contracts
  • Multi-Contract Aggregation: Pass an array of addresses to filter events from multiple contracts in a single filter

Error Handling

Error CodeMessageDescription
-32602Invalid paramsFilter object is malformed or block range is invalid
-32603Internal errorNode failed to create the filter

Web3 Integration

ethers-example.js

javascriptimport { ethers } from 'ethers';

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

const filter = {
    address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
    topics: ['0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'],
};
provider.on(filter, (log) => {
    console.log('Transfer log:', log);
});

const filterId = await provider.send('eth_newFilter', [{
    fromBlock: 'latest',
    address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
    topics: ['0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'],
}]);
console.log('Filter ID:', filterId);

viem-example.js

javascriptimport { createPublicClient, http } from 'viem';
import { mainnet } from 'viem/chains';

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

const filter = await client.createEventFilter({
    address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
    event: {
        type: 'event',
        name: 'Transfer',
        inputs: [
            { indexed: true, name: 'from', type: 'address' },
            { indexed: true, name: 'to', type: 'address' },
            { indexed: false, name: 'value', type: 'uint256' },
        ],
    },
});
console.log('Filter ID:', filter.id);