ethers.js: Error on Events triggering

Ethers Version

6.02

Search Terms

events, event

Describe the Problem

While creating event listeners upon receipt of event an error occurs. Simplified example provided. This is occurring for multiple contracts and events. Switching to v5.7.2 the events work fine.

Code Snippet

const { ethers } =  require(`ethers`);

const newEthersClient = new ethers.providers.JsonRpcProvider('https://rpc.ankr.com/polygon/486f6d938d85e35aeacf83a59afd95c4fab739093c8f919adb258799d81d51bf');

abi = [
    "event Transfer(address indexed from, address indexed to, uint amount)"
  ]
  
  contract = new ethers.Contract("0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063", abi, newEthersClient)
  
  // Begin listening for any Transfer event
  contract.on("Transfer", (from, to, _amount, event) => {
    const amount = ethers.formatEther(_amount, 18)
    console.log(`${ from } => ${ to }: ${ amount }`);
  
    // The `event.log` has the entire EventLog
  
    // Optionally, convenience method to stop listening
    event.removeListener();
  });

Contract ABI

[
    "event Transfer(address indexed from, address indexed to, uint amount)"
  ]

Errors

Uncaught TypeError TypeError: unknown ProviderEvent (argument="event", value="{\"topics\":[\"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef\"],\"address\":[\"0x8f3cf7ad23cd3cadbd9735aff958023239c6a063\"]}", code=INVALID_ARGUMENT, version=6.0.2)

Environment

node.js (v12 or newer)

Environment (Other)

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 2
  • Comments: 28 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Sorry. Lost track of this. I will look into it today.

Just tested and seems to be working on JsonRPC but still same error if i try with a websocket.

This should now be fixed for WebSocketProvider in v6.2.3.

Please try it out and let me know if there are further issues.

Thanks! 😃