eth_newFilter
Creates a filter object on XDC Network to notify when state changes (logs).
Use Cases#
- Event monitoring - Subscribe to contract events
- Real-time updates - Track events for tokenized trade finance (Letters of Credit, Bills of Lading), cross-border payments, and real-world asset tokenization
- Indexing - Build event indexes incrementally
Parameters#
| Parameter | Type | Required | Description |
|---|---|---|---|
fromBlock | QUANTITY|TAG | No | Starting block |
toBlock | QUANTITY|TAG | No | Ending block |
address | DATA|Array | No | Contract address(es) |
topics | Array | No | Topic filters |
Request#
{
"jsonrpc": "2.0",
"method": "eth_newFilter",
"params": [{
"fromBlock": "latest",
"address": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
"topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]
}],
"id": 1
}
Returns#
| Type | Description |
|---|---|
QUANTITY | Filter ID |
Code Examples#
- cURL
- JavaScript
curl -X POST https://api-xdc-mainnet.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_newFilter",
"params": [{
"fromBlock": "latest",
"address": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb"
}],
"id": 1
}'
import { JsonRpcProvider } from 'ethers';
const provider = new JsonRpcProvider('https://api-xdc-mainnet.n.dwellir.com/YOUR_API_KEY');
// Create filter
const filterId = await provider.send('eth_newFilter', [{
fromBlock: 'latest',
address: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
topics: ['0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef']
}]);
// Poll for changes
const changes = await provider.send('eth_getFilterChanges', [filterId]);
console.log('New events:', changes);
// Cleanup
await provider.send('eth_uninstallFilter', [filterId]);
Related Methods#
eth_getFilterChanges- Poll filter for changeseth_uninstallFilter- Remove filtereth_getLogs- Direct log query