curl --request POST \
--url https://nd-363-550-219.p2pify.com/942aad90bb6a082676497030b81e40ba \
--header 'Content-Type: application/json' \
--data '{
"method": "eth_newFilter",
"params": [
{
"fromBlock": "latest",
"address": "0x4F9A0e7FD2Bf6067db6994CF12E4495Df938E6e9",
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
]
}
],
"id": 1,
"jsonrpc": "2.0"
}'
{
"jsonrpc": "<string>",
"id": 123,
"result": "<string>"
}
curl --request POST \
--url https://nd-363-550-219.p2pify.com/942aad90bb6a082676497030b81e40ba \
--header 'Content-Type: application/json' \
--data '{
"method": "eth_newFilter",
"params": [
{
"fromBlock": "latest",
"address": "0x4F9A0e7FD2Bf6067db6994CF12E4495Df938E6e9",
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
]
}
],
"id": 1,
"jsonrpc": "2.0"
}'
{
"jsonrpc": "<string>",
"id": 123,
"result": "<string>"
}
object
— the filter parameters:
fromBlock
— (optional, default: latest
) integer that specifies the starting block number from which the logs should be fetched.toBlock
— (optional, default: latest
) integer that specifies the ending block number until which the logs should be fetched.address
— (optional) the contract address from which the logs should be fetched. It can be a single address or an array of addresses.topics
— (optional) an array of DATA
topics. The event topics for which the logs should be fetched. It can be a single topic or an array of topics.blockhash
— (optional) the hash of the specific block. Limits logs to a specific block with a 32-byte hash value. It takes precedence over fromBlock
and toBlock
.latest
— the most recent block in the blockchain and the current state of the blockchain at the most recent blockearliest
— the earliest available or genesis blockpending
— the pending state and transactions block. The current state of transactions that have been broadcast to the network but have not yet been included in a block.result
— a hexadecimal string representing the ID of the newly created filtereth_newFilter
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 filter = {
toBlock: 'latest',
address: '0x4F9A0e7FD2Bf6067db6994CF12E4495Df938E6e9',
topics: ['0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef']
};
const createFilter = async () => {
try {
const filterId = await provider.send('eth_newFilter', [filter]);
console.log(filterId); // the filter ID returned by eth_newFilter
return filterId
} catch (error) {
console.log(error);
}
};
createFilter();
eth_newFilter
to create a filter for a specific action on a smart contract, for example, to monitor the transfer transactions from the Wrapped ETH token.
The idea is to create a filter using the eth_newFilter
method to monitor an ERC-20 smart contract, WETH in this case.The filter ID.
The response is of type object
.
Was this page helpful?