Node RPC
  • Introduction
  • Ethereum API endpoints
    • eth_getBlockByHash
    • eth_blocknumber
    • eth_getBlockByNumber
    • eth_getBlockTransactionCountByHash
    • eth_getBlockTransactionCountByNumber
    • eth_getTransactionByHash
    • eth_getTransactionByBlockHashAndIndex
    • eth_getTransactionByBlockNumberAndIndex
    • eth_getTransactionReceipt
    • eth_getTransactionCount
    • eth_sendRawTransaction
    • eth_call
    • eth_getCode
    • eth_getBalance
    • eth_accounts
    • eth_getStorageAt
    • eth_getProof
    • eth_getLogs
    • eth_newFilter
    • eth_newPendingTransactionFilter
    • eth_newBlockFilter
    • eth_getFilterChanges
    • eth_getFilterLogs
    • eth_uninstallFilter
    • eth_chainId
    • eth_protocolVersion
    • net_listening
    • net_version
    • eth_getUncleCountByBlockHash
    • eth_getUncleByBlockNumberAndIndex
    • eth_getUncleByBlockHashAndIndex
    • eth_getUncleCountByBlockNumber
    • eth_estimateGas
    • eth_gasPrice
    • eth_feeHistory
    • eth_maxPriorityFeePerGas
    • eth_createAccessList
    • web3_clientVersion
    • web3_sha3
Powered by GitBook
On this page
  • Parameters
  • Returns
  • Example
  1. Ethereum API endpoints

eth_newFilter

Previouseth_getLogsNexteth_newPendingTransactionFilter

Last updated 1 year ago

Creates a filter object, based on filter options, to notify when the state changes (logs). To check if the state has changed, call .

NOTE: We enforce a limit of 10,000 block ranges when requesting logs and events. The 10,000 block range limit is not a limit on how far back in time you can query but rather a limit on the number of blocks you can query in a single request. To work around the limit, we recommend breaking down your queries into smaller chunks of 10,000 blocks or less.

NOTE: Topics are order-dependent. A transaction with a log with topics [A, B] will be matched by the following topic filters:

  • [] "anything"

  • [A] "A in first position (and anything after)"

  • [null, B] "anything in first position AND B in second position (and anything after)"

  • [A, B] "A in first position AND B in second position (and anything after)"

  • [[A, B], [A, B]] "(A OR B) in first position AND (A OR B) in second position (and anything after)"

Parameters

  1. Object - The filter options:

  • fromBlock: QUANTITY|TAG - (optional, default: "latest") Integer block number, or "latest" for the last mined block or "pending", "earliest" for not yet mined transactions.

  • toBlock: QUANTITY|TAG - (optional, default: "latest") Integer block number, or "latest" for the last mined block or "pending", "earliest" for not yet mined transactions.

  • address: DATA|Array, 20 Bytes - (optional) Contract address or a list of addresses from which logs should originate.

  • topics: Array of DATA, - (optional) Array of 32 Bytes DATA topics. Topics are order-dependent. Each topic can also be an array of DATA with "or" options.

Returns

QUANTITY - A filter id.

Example

Query

import { ethers } from 'ethers';

const provider =
  new ethers
    .providers
    .JsonRpcProvider("https://www.noderpc.xyz/rpc-mainnet/public")

const fetchLogs = async ()=> {
  const filter = {
    fromBlock: "0xe20360",
    toBlock: "0xe20411",
    address: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
    topics: [],
  };
  const filterId = await provider.send("eth_newFilter", [filter]);
  console.log(filterId);

}
fetchLogs();

Result

0x0700000000000000f9383206a08e58ea

NOTE: In this example we are using public Ethereum endpoint. Ideally, for your own projects, you should use your own endpoint, which you can generate for free by connecting to your wallet .

NOTE: ethers used below is a well-known web3 library, check it out .

eth_getFilterChanges
here
here