For the complete documentation index, see llms.txt. This page is also available as Markdown.

eth_newBlockFilter - Optimism

Example code for the eth_newBlockFilter json-rpc method. Сomplete guide on how to use eth_newBlockFilter json-rpc in GetBlock.io Web3 documentation.

This method creates a filter that can be polled to receive notifications about new blocks. Use eth_getFilterChanges to retrieve the hashes of new blocks since the last poll. With Optimism's ~2-second block time, near real-time block tracking is possible.

Parameters

  • None

Request Sample

curl --location 'https://shared.us-east-1.getblock.io/<ACCESS_TOKEN>' \
--header 'Content-Type: application/json' \
--data '{
   "jsonrpc": "2.0",
    "method": "eth_getUncleCountByBlockNumber",
  "params": [
  ],
    "id": "getblock.io"
}'
import axios from 'axios'
let data = JSON.stringify({
    "jsonrpc": "2.0",
     "method": "eth_getUncleCountByBlockNumber",
  "params": [
  ],
    "id": "getblock.io"
};

let config = {
  method: "post",
  maxBodyLength: Infinity,
  url: "https://shared.us-east-1.getblock.io/<ACCESS_TOKEN>",
  headers: {
    "Content-Type": "application/json",
  },
  data: data,
};

axios
  .request(config)
  .then((response) => {
    console.log(JSON.stringify(response.data));
  })
  .catch((error) => {
    console.log(error);
  });

Response

A successful response returns the following:

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

Response Parameters

  • id: A unique request identifier, matching the id sent in the request body.

  • jsonrpc: Specifies the use of JSON-RPC version 2.0.

  • result: A filter ID that can be used with eth_getFilterChanges.

Use Case

The eth_newBlockFilter method is commonly used for:

  • Block monitoring

  • Chain progression tracking

  • Block-based triggers

  • Real-time updates

Integration with Web3

Last updated

Was this helpful?