Node server using infura not catching new events

I previously was using a local parity node. I simply switched out one line of code so that it uses infura, and it is no longer catching new events. It catches them all if I close and restart the program- but if the server is running, it isnt catching anything anymore? What’s going on?

Hi @mcplums, could you provide your code so we can help you debug this?

Sure :slight_smile: this is my node.js server. It works great when I first launch the server, and will trigger the saveReview function for all events found. But after its running, if I trigger a new event on the blockchain, the node.js doesn’t see it until I restart it.

var DrewsReviewsArtifact = require("../build/contracts/DrewsReviews.json");
var Web3 = require('web3')

web3 = new Web3(new Web3.providers.WebsocketProvider('wss://mainnet.infura.io/ws/v3/key'))

web3.eth.net.getId().then(function(networkId) {
    const deployedNetwork = DrewsReviewsArtifact.networks[networkId];
    instance = new web3.eth.Contract(
        DrewsReviewsArtifact.abi,
        deployedNetwork.address,
    );

    setupReviewEventListener(instance);
})


function setupReviewEventListener(i) {
    i.events.newReview({
        fromBlock: 0
    }, (error, event) => {
        saveReview(event.returnValues);
    })
}

}

Do you have a rough estimate of how long the app is running before the event stops returning?

Hey sorry, I was not clear. It ONLY works when I initially launch the server. If I trigger an event ten seconds after I launch the server, the code will not catch it. Ie it checks all events once when it is initiated, and never again.

Have you tried doing this separate from web3.js to rule out an error there? Using something like wscat?

No I have not. I will see if I can find the time to do that! I have not used wscat before so it may take a while to get it sorted and I am very busy at the moment :frowning: but thank you for your help and let me know if you think of anything else in the meantime :slight_smile:

I appreciate your help and apologise that I am replying by saying I am too busy to try your solution (I’m sure you’re very busy as well!) but that is the situation unfortunately!