Provider.on("block") correct order #3183
-
I am not sure if this is an ethers problem or just the way JS works (I don't have a lot of experience with javascript). I am listening for new blocks, but sometimes the blocks are out of order when I get the block's data: provider.on("block", async (n) => {
const block = await provider.getBlock(n);
console.log(block.number.toString());
}); In this case, n is always in correct order. But when I fetch the block (provider.getBlock(n)), sometimes the block does not come in the same order, e.g : 15161559 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Put a Once you do an |
Beta Was this translation helpful? Give feedback.
Put a
console.log(n)
before theawait
, and you should see the events are occurring in the correct order.Once you do an
await
though, you are queuing a bunch of things that can then occur in any order from the event queue, depending on the when the network responds.