Ethers.js: Events returned by WebSocketProvider inconsistent with getLogs

Created on 22 Apr 2020  路  7Comments  路  Source: ethers-io/ethers.js

Hi @ricmoo ,

When I receive an event via Websockets, the event.blockNumber appears in hex (but otherwise seems to work fine).

However, when I do provider.getLogs() (using normal Infura provider), the log.blockNumber is in decimal format.

My assumption has been that a log (using normal provider) and a Websocket event are the same type of object. Is that correct? Should both be returning decimal blockNumber?

Thanks!

bug fixed

Most helpful comment

Both should be returning a decimal. You are right, the subscribed events in the WebSocketProvider is skipping the regular wrapping for block, but logs are still wrapped properly. I鈥檒l fix it shortly. And double check everything else is being normalized correctly. :)

All 7 comments

Both should be returning a decimal. You are right, the subscribed events in the WebSocketProvider is skipping the regular wrapping for block, but logs are still wrapped properly. I鈥檒l fix it shortly. And double check everything else is being normalized correctly. :)

Actually... I can't reproduce this and the place I thought might be left unguarded seems to wrap the call correctly. Can you include a snippet of code? Also, what backend are you using?

These seem to all work:

provider.getBlockNumber().then((b) => {
    console.log("getBlockNumber", b);
});

provider.on("block", (b) => {
    console.log("event", b);
    console.log("per event", provider.blockNumber);
});

Oh! Misread... One sec. :)

No wait... I didn't misread, please pass along a code snippet. :)

I can confirm that the block numbers are returned correctly for your code snippets above.

The issue I'm encountering is when listening for events:

    // Listen for all contract events.
    wsContract.on("*", (event) => {
      console.log("New event from block: ", event.blockNumber); // Returns a hex value
    });

Found the problem. I'll publish after the CI completes. :)

This should be fixed in 5.0.0-beta.183. Try it out and let me know. :)

It's working! Thank you.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thegostep picture thegostep  路  3Comments

moshebeeri picture moshebeeri  路  3Comments

pcowgill picture pcowgill  路  3Comments

zemse picture zemse  路  3Comments

ricmoo picture ricmoo  路  3Comments