Hello @traian.vila,
for people having the same issue, i found the mistakes i was doing:
Error number 1: I was using a wrong wss link.
I was using wss://kovan.infura.io/v3/[projectId] instead of wss://kovan.infura.io/ws/v3/[projectId]
Its strange it worked for some events, but it was wrong nonetheless.
Error number 2: when getting the provider to use in the listener i was conecting to the websocket but when instantiating the contract, i was using a http provider. Something like this:
//THIS WAS RIGHT
const _web3Socket: WebsocketProvider = new Web3.providers.WebsocketProvider(
wss://kovan.infura.io/ws/v3/[projectId],
{
// @ts-ignore
clientConfig: {
keepalive: true,
keepaliveInterval: 60000,
},
}
);
let web3ProviderFromSocket = new Web3(_web3Socket);
_web3Socket.on(“connect”, function () {
console.log(“WSS Connected”);
});
_web3Socket.on(“close”, function () {
console.log(“WS closed”);
console.log(“Attempting to reconnect…”);
_web3Socket= [new web3Socket connection];
_web3Socket.on(“connect”, function () {
console.log(“WSS Reconnected”);
});
web3ProviderFromSocket.setProvider(_web3Socket);
});
_web3Socket.on(“error”, function () {
console.error(WS Error!
);
});
but then, when instantiating the contract, i was using a http provider, like this:
THIS WAS WRONG
const _web3Provider = new Web3(“https://kovan.infura.io/v3/[projectId]”);
var web3Contract = new _web3Provider.eth.Contract(
Contract.abi as AbiItem[],
ContractAddress
);
let contractSubObject = web3Contract.events.allEvents({
fromBlock: [currentBlockNumber],
});
contractSubObject
.on(“connected”, function (subId) {
console.log(
Contract Subscription active with subscription id ${subId}
);
})
.on(“data”, async function (event) {
let eventName = event.event.toLowerCase();
if (eventName == []the event i want]){
//do my code
}
})
It caused this strange behavior where some events were firing and others dont.
the correct way was to use the web3ProviderFromSocket to instantiate the contract.
after i corrected both things, things are working smoothly.
Hope i can help other people!