0

I have a problem with connecting via Websockets to Infura. I am listening on some events from my smart contract, so when some event is dispatched by calling some method from smart contract, I should catch that event and do some stuff inside callback. Actually this seems to work locally(localhost), so I am connecting to Infura via Websockets without problem and everything works fine.

The problem occurs when a backend is deployed on aws instance. So the WebSocket connection to that AWS instance cannot be done and the most strangest thing is that I don't get any errors. Here is the code:

const web3Socket = new Web3(new Web3.providers.WebsocketProvider("wss://ropsten.infura.io/ws"));
...
...
...
let instance = await new web3Socket.eth.Contract(contractAbi, address);
 instance.events.transactionEvent({
        fromBlock: "latest"
    }, (error, event) => { console.log(event); })
        .on('data', async (event) => {
            // do some stuff
        })
        .on('changed', function(event){
            console.log('CHANGED');
            console.log(event);
            // remove event from local database
        })
        .on('error', console.error);
...
...
...

So actually .on('error', console.error); is not throwing any error for example connection lost or connection refused. Any tips/suggestions on what to try next or what can cause the issue?

1

According to this, the web3 provider URL should look something like:

wss://ropsten.infura.io/ws/v3/YOUR-PROJECT-ID

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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