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!
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.
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. :)