3

I am writing an integration test and I need to get the number of all the past events using ether.js. The issue I am having is that it seems like I receive only 1 event even though there should be 4 in total. Here is the code I use:

  const provider = new ethers.providers.JsonRpcProvider(TEST_JSON_RPC)
  const loanVaultFactory = new ethers.Contract(
    address,
    abi,
    provider.getSigner(0)
  )
  let events = loanVaultFactory.filters.LoanVaultCreated()
  console.log(events)

And this is the output:

{
  address: '0x27e8A5B8Af57aEE27A33247D867ED52173876791',
  topics: [
    '0x2c80e53ce4a0770abb7d3436ea6bc5ff59702f84b0d9378b4c58cc59e4618042'
  ]
}

I would expect there to be 4 items in the topics list. Am I doing something wrong with the filters? Thank you

Jan Beneš
  • 569
  • 1
  • 7
  • 14

1 Answers1

19

The filter method doesn't return the events but the filter object. To get the events you have to pass the filter to the contract.queryFilter method:

  const contract = new ethers.Contract(
    address,
    abi,
    provider.getSigner(0)
  )
  let eventFilter = contract.filters.ContractEvent()
  let events = await contract.queryFilter(eventFilter)
Jan Beneš
  • 569
  • 1
  • 7
  • 14