question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

EventFilter type doesn't have fromBlock and toBlock fields, even though those are processed and necessary

See original GitHub issue

Using this filter:

const filter = myContract.filters.MyEvent();
const events = await myProvider.getLogs(filter);

I only get the latest event, but if I do this…

const filter = myContract.filters.MyEvent() as any;
filter.fromBlock = 0;
filter.toBlock = "latest";
const events = await myProvider.getLogs(filter);

I correctly get all events.

The cast to any is necessary because the type EventFilter doesn’t have fromBlock and toBlock fields.

Unless I’m misunderstanding something, this seems wrong.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ricmoocommented, Dec 14, 2020

@felixwatts Heya! Sorry for the late reply.

Those docs are out of date, and I will get redirects configured for them this week. The docs you are looking for are here: https://docs.ethers.io/v5/api/contract/contract/#Contract-queryFilter

Thanks @zemse !

1reaction
zemsecommented, Nov 11, 2020
const filter = myContract.filters.MyEvent();
const events = await myContract.queryFilter(filter);

This should work. And about the provider.getLogs, I wanted to bring that up before, but I forgot.

> provider.getLogs(filter);
[]

It returns empty array instead of error. I unfortunately ran into this when I was demonstrating in an event 😜 and needed to look at old working code. I suggest that if fromBlock and toBlock is not passed then it should fill in the blanks. filter.fromBlock = 0; filter.toBlock = "latest"; or at least give an error that this key wasn’t passed.

Edit: I see that typescript might point that out, but the JS should also do that (I actually demo in browser console using the exposed window._ethers).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Event filter not returning correct events web3js
I have just 2 events with different values of the "epc" field. The response I get is the latest event but with the...
Read more >
Everything You Ever Wanted to Know About Events and Logs ...
Understand Events and Logs in Ethereum, how to make an event scraper, and how to implement event pagination.
Read more >
EventFilters and EventFilter.Item - SAP Community
Hi, I have 2 questions about using EventFilter and the EventFilter.item method. ... forms does not open when you click them if the...
Read more >
Documentation - Ethers.js
Returns the number of transactions address has ever sent, as of blockTag. This value is required to be the nonce for the next...
Read more >
web3.js Documentation - Read the Docs
After that you need to create a web3 instance and set a provider. ... indexed: true if the field is part of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found