I'm trying to listen to all emitted events from a contract with Ethers.js and Websockets.

Any idea why this is not working?

var wsProvider = new ethers.providers.WebSocketProvider("wss://rinkeby.infura.io/ws/v3/idhere");

let contract = new ethers.Contract(rinkebyAddress, CONTRACT_ABI, wsProvider);

contract.on("*", (from, to, value, event) => {
  console.log("event: ", event);

The websockets connection seems to work because this returns all new blocks:

wsProvider.on('block', (blockNumber) => {
  console.log('New Block: ' + blockNumber);

Its because you have to specify the network type, otherwise it will take mainnet as default if not provided

also make sure your infura provider websocket is for rinkeby/supports rinkeby

var wsProvider = new ethers.providers.WebSocketProvider("wss://rinkeby.infura.io/ws/v3/idhere", "rinkeby");

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.