eth_getFilterChanges | Fantom

Fantom API polling method used to retrieve updates from a filter. A filter is an object used to track changes to the state of the blockchain.

πŸ‘

Get you own node endpoint today

Start for free and get your app to production levels immediately. No credit card required.

You can sign up with your GitHub, X, Google, or Microsoft account.

Filters can be created using one of the following methods:

After creating a filter using one of the available methods, the resulting filter ID can be used to fetch changes by calling the eth_getFilterChanges method.

🚧

Disclaimer

Note that the default interactive example in this page will not work as the filter will be expired.

To test eth_getFilterChanges in this page, first create a new filter using one of the following:

Then use the fresh filter ID as the parameter for eth_getFilterChanges.

Parameters

  • string β€” the filter ID of the filter for which you want to retrieve the changes

Response

  • array β€” an array that represents the changes that have occurred on the blockchain since the last time the filter was polled:
    • For filters created with eth_newBlockFilter:
      • blockHash β€” the hashes of the new blocks since the last time the filter was polled.
    • For filters created with eth_newPendingTransactionFilter:
      • transactionHash β€” the hashes identifying new pending transactions since the last time the filter was polled.
    • For filters created with eth_newFilter, the following event logs:
      • address β€” the contract address from which the event originated.
      • topics β€” an array of 32-byte data fields containing indexed event parameters.
      • data β€” the non-indexed data that was emitted along with the event.
      • blocknumber β€” the block number in which the event was included. null if it is pending.
      • transactionhash β€” the hash of the transaction that triggered the event. null if pending.
      • transactionindex β€” the integer index of the transaction within the block's list of transactions. null if it is pending.
      • blockhash β€” the hash of the block in which the event was included. null if it is pending.
      • logindex β€” the integer identifying the index of the event within the block's list of events. null if pending.
      • removed β€” the boolean value indicating if the event was removed from the blockchain due to a chain reorganization. True if the log was removed. False if it is a valid log.

eth_getFilterChanges code examples

πŸ“˜

Note that the web3.eth.filter methods have been deprecated and replaced with the web3.eth.subscribe in web3.js. See web3.js subscriptions.

const ethers = require('ethers');
const NODE_URL = "CHAINSTACK_NODE_URL";
const provider = new ethers.JsonRpcProvider(NODE_URL);

async function getFilterChanges(filter) {
  try {
    const changes = await provider.send('eth_getFilterChanges', [filter]);
    console.log(changes); // Log the with the new data
  } catch (err) {
    console.error(err); // Handle errors that may occur
  }
}

const filterId =  '0x4e7ef166cd43f188b0f8f9e218966a8f' //'YOUR_FILTER_iD'
getFilterChanges(filterId)
from web3 import Web3  
node_url = "CHAINSTACK_NODE_URL" 
web3 = Web3(Web3.HTTPProvider(node_url))

def get_filtered_events(filter_id):
    try:
        filter_changes = web3.eth.get_filter_changes(filter_id)
        print(filter_changes) # the array of events that match the filter
    except Exception as e:
        print(e)

filter_id = '0x0'
get_filtered_events(filter_id)       

Use case

The eth_getFilterChanges method can poll a filter to periodically retrieve new data. You can, for example, create a blocks filter using eth_newBlockFilter and periodically poll it to get new blocks.

Try the eth_getFilterChanges RPC method yourself

Language
Click Try It! to start a request and see the response here!