ETIMEDOUT after some time on Mainnet (Ethers.js and Infura)

Hello everyone,

I seem to have run into an issue, where i get simple event responses on new blocks, and then i make a new call after that again.

After like 5-10 calls or so, it gives an ETIMEDOUT error , and i cant understand why.
Would appreciate all the help i could get.

This is the error it gives.

And here is my code:

const { ethers } = require(“ethers”);
let network = “mainnet”;

const provider = new ethers.providers.InfuraProvider(network, ‘24254d9e2dc5439a841745f0c5e03a31’);
provider.pollingInterval = 20000;

provider.on(‘block’, async (tx) => {
console.log(“New block tx in “+network+”'s networks”, tx)
let block = await provider.getBlockWithTransactions(tx)
let transactions = block.transactions;
//check each transaction in the block
transactions.forEach(transaction => {
//if transaction contains any of the array ones.
if( == “0x704cEF323aa8ac769C52fb61d32Db0a788CD3018”) {
console.log(“We have the transaction”, transaction)
let txid = transaction.hash;

Best regards, Robo

Hi Robo!

Welcome to our community! We’re working on figuring this issue out and will get back to you soon with an answer.

Hi Robo,

Thanks for your patience! After working on this for some time, I’m having a hard time recreating your error; I’ve had it running for about 10 min and it’s still going strong (77 calls and counting).

It appears you’re getting an “Unhandled Promise Rejection Warning” with a “missing response” error, which is what I believe may be causing that timeout.

Do you define the getBlockWithTransactions function elsewhere in your code? If not, that may be causing the error message to show.