I’m working on a project where I need to track USDT transfers to specific wallet addresses and confirm them after a certain number of blocks. I’m using ethers.js to fetch logs for this purpose. However, I keep getting empty results from getLogs despite knowing there are relevant transactions. I checked Etherscan and there are transfers for that address.
Here is the relevant part of my code:
import { ethers, id } from 'ethers';
import { AppDataSource } from './config/data-source';
import { PaymentIntent } from './entity/PaymentIntent';
import { Repository } from 'typeorm';
const provider = new ethers.WebSocketProvider('wss://mainnet.infura.io/ws/v3/60df93ecf023472aaa84725af955fde2');
async function registerConfirmationChecker(walletAddress: string, paymentIntentId: number): Promise<void> {
console.log(`Registering confirmation checker for wallet: ${walletAddress}`);
provider.on('block', async (blockNumber) => {
console.log(`New block received: ${blockNumber}`);
const paymentIntentRepository: Repository<PaymentIntent> = AppDataSource.getRepository(PaymentIntent);
const paymentIntent = await paymentIntentRepository.findOne({
where: { address: walletAddress, status: 'paid' },
relations: ['user']
});
if (paymentIntent) {
console.log(`Processing payment intent: ${paymentIntent.id}`);
const filter = {
address: walletAddress,
fromBlock: blockNumber - 20,
toBlock: blockNumber,
topics: [
id("Transfer(address,address,uint256)")
]
};
console.log(`Fetching logs with filter: ${JSON.stringify(filter)}`);
try {
const logs = await provider.getLogs(filter);
console.log(`Filter result: ${JSON.stringify(logs)}`);
} catch (error) {
console.error(`Error fetching logs:`, error);
}
} else {
console.log(`No payment intent found for wallet address: ${walletAddress}`);
}
});
console.log(`Confirmation checker registered for wallet: ${walletAddress}`);
}
LOGS:
Fetching logs with filter: {"address":"0x2d8fd1524d138c47b7999104087ce198e2a88f4b","fromBlock":20276500,"toBlock":20276520,"topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}
Filter result: []
No logs found for payment intent: 13
New block received: 20276604
Processing payment intent: 13
Fetching logs with filter: {"address":"0x2d8fd1524d138c47b7999104087ce198e2a88f4b","fromBlock":20276501,"toBlock":20276521,"topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}
Filter result: []
No logs found for payment intent: 13
New block received: 20276605
Processing payment intent: 13
Fetching logs with filter: {"address":"0x2d8fd1524d138c47b7999104087ce198e2a88f4b","fromBlock":20276502,"toBlock":20276522,"topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}
Filter result: []
No logs found for payment intent: 13