I'm running a hardhat node and a nodejs backend using web3js to capture events (code) and for some reason the events stop getting caught by web3js.

The transactions seem to be firing just fine as I can see them in the logs, but the backend isn't picking them up.

This is all being run in separate docker containers on a c5.xlarge ec2 instance on aws.

I tried increasing the instance class for more memory even though there was memory to spare, so not sure how to troubleshoot from here.

And the contact does emit events successfully at the beginning just not after a period of time. And also if I comment out some of the initial tests, the tests that time out due to the event not being captured succeed.

You can recreate the issue by running the unit tests for this repo (https://github.com/DAPPNetworkLabs/dapp-workers/) with:


Be sure to add a .config.json to ./eth/.config.json and ./nexus/.config.json so hardhat has the proper alchemy (https://www.alchemy.com/) keys for forking the ETH mainnet.

    "alchemyKey": ""

2 Answers 2


Your Web3 Websocket may disconnect once in a while. To handle this configure it to reconnect automatically, use this code in web3global.ts -

export let provider = new Web3.providers.WebsocketProvider(process.env.ETH_ADDR, {
    reconnect: {
        auto: true,
        delay: 1000,
        onTimeout: false,
    timeout: 45000,
    clientConfig: {
        maxReceivedFrameSize: 50000000000,
        maxReceivedMessageSize: 50000000000,
        keepalive: true,
        keepaliveInterval: 10000,
        dropConnectionOnKeepaliveTimeout: true,
        keepaliveGracePeriod: 30000,
provider.on("connect", () => {
provider.on("reconnect", () => {
provider.on("close", () => {
export let web3 = new Web3(provider);

The issue was with the alchemy free tier.

Free tier users will be limited to 10 concurrent requests per WebSocket connection.

After receiving the desired event or hitting a timeout you can use the following to unsubscribe from the event if using ethers js.

await contract.removeAllListeners(event);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.