Skip to main content
Monad API method that creates a filter in the node to notify when a new block arrives. Use eth_getFilterChanges to poll for new blocks.
Get you own node endpoint todayStart 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.

Parameters

  • none

Response

  • result — the filter ID, used to poll for new blocks with eth_getFilterChanges.

eth_newBlockFilter code examples

const { ethers } = require("ethers");

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

async function createBlockFilter() {
  const filterId = await provider.send("eth_newBlockFilter", []);
  console.log("Filter ID:", filterId);

  // Poll for new blocks
  setInterval(async () => {
    const changes = await provider.send("eth_getFilterChanges", [filterId]);
    if (changes.length > 0) {
      console.log("New blocks:", changes);
    }
  }, 2000);
}

createBlockFilter();

Use case

A practical use case for eth_newBlockFilter is building applications that need to react to new blocks as they are mined, such as block explorers, monitoring tools, or applications that need to track chain progress without using WebSocket subscriptions.