curl --request POST \
--url https://bsc-mainnet.core.chainstack.com/35848e183f3e3303c8cfeacbea831cab \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"method": "eth_newBlockFilter",
"params": [],
"id": 1
}'
{
"jsonrpc": "<string>",
"id": 123,
"result": [
"<string>"
]
}
curl --request POST \
--url https://bsc-mainnet.core.chainstack.com/35848e183f3e3303c8cfeacbea831cab \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"method": "eth_newBlockFilter",
"params": [],
"id": 1
}'
{
"jsonrpc": "<string>",
"id": 123,
"result": [
"<string>"
]
}
eth_newBlockFilter
method is useful for developers who must be notified of new blocks on the blockchain in real-time.
none
result
— a hexadecimal string representing the ID of the newly created filter.eth_newBlockFilter
code examplesweb3.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);
const createFilter = async () => {
try {
const filterId = await provider.send('eth_newBlockFilter', []);
console.log(filterId); // the filter ID returned by eth_newFilter
return filterId
} catch (error) {
console.log(error);
}
};
createFilter();
eth_newBlockFilter
in a simple DApp is to listen for new blocks and update the user interface with the latest block information.
When the DApp starts, it creates a new filter using eth_newBlockFilter
to listen for new blocks. When a new block is added to the blockchain, the filter is triggered, and the DApp retrieves the latest block information using a Web3 library.The new filter ID.
The response is of type object
.