Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get block timestamp for WebSockets event? #856

Closed
bbarton opened this issue May 28, 2020 · 4 comments
Closed

How to get block timestamp for WebSockets event? #856

bbarton opened this issue May 28, 2020 · 4 comments
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.

Comments

@bbarton
Copy link

bbarton commented May 28, 2020

Hi @ricmoo ,

WebSockets events are being received perfectly.

However, when an event comes in, the following returns null:

block = await jsonRpcProvider.getBlock(event.blockNumber); // block is null; the regular provider apparently doesn't know about this block yet.
const creationTime = block.timestamp; // Block is null, so this fails.

Any ideas on how to get the block timestamp when a Websocket event is received? Thanks for your help!

@ricmoo ricmoo added bug Verified to be an issue. on-deck This Enhancement or Bug is currently being worked on. labels May 29, 2020
@ricmoo
Copy link
Member

ricmoo commented May 29, 2020

The polling-based providers track this extra state internally to prevent this from happening. I didn't properly cache the block emitted event in the WebSocketProvider to leverage this behaviour from the BaseProvider.

I've got a fix locally and it should be published tomorrow. I'll update this ticket with the progress.

Thanks! :)

@ricmoo
Copy link
Member

ricmoo commented May 30, 2020

This should be fixed now in 5.0.0-beta.189. Please try it out and let me know if you still have any problems. :)

@ricmoo ricmoo added fixed/complete This Bug is fixed or Enhancement is complete and published. and removed on-deck This Enhancement or Bug is currently being worked on. labels May 30, 2020
@ricmoo
Copy link
Member

ricmoo commented Jun 3, 2020

I'm going to close this now, since I think it is fixed. If not, please re-open.

Thanks! :)

@ricmoo ricmoo closed this as completed Jun 3, 2020
@bbarton
Copy link
Author

bbarton commented Jun 4, 2020

Thanks @ricmoo ; all is good on my end!

michaeltout pushed a commit to michaeltout/ethers.js that referenced this issue Aug 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.
Projects
None yet
Development

No branches or pull requests

2 participants