import * as FilterId from './primitives/FilterId/index.js';
import * as LogFilter from './primitives/LogFilter/index.js';
import * as Address from './primitives/Address/index.js';
// Create log filter
const filter = LogFilter.from({
fromBlock: "latest",
address: Address.from("0x..."),
topics: [eventSignature]
});
// Install filter on node
const filterIdStr = await rpc.eth_newFilter(filter);
const filterId = FilterId.from(filterIdStr);
// Poll every 15 seconds
const interval = setInterval(async () => {
try {
const logs = await rpc.eth_getFilterChanges(filterId);
console.log(`Got ${logs.length} new logs`);
} catch (error) {
// Filter expired - recreate
if (error.message.includes('filter not found')) {
clearInterval(interval);
// Recreate filter...
}
}
}, 15000);
// Cleanup
process.on('SIGINT', async () => {
await rpc.eth_uninstallFilter(filterId);
clearInterval(interval);
});