trufflesuite / truffle

:warning: The Truffle Suite is being sunset. For information on ongoing support, migration options and FAQs, visit the Consensys blog. Thank you for all the support over the years.
https://consensys.io/blog/consensys-announces-the-sunset-of-truffle-and-ganache-and-new-hardhat?utm_source=github&utm_medium=referral&utm_campaign=2023_Sep_truffle-sunset-2023_announcement_
MIT License
14.02k stars 2.32k forks source link

myContract.MyEvent() doesn't accept filter options #1170

Closed pstuermlinger closed 6 years ago

pstuermlinger commented 6 years ago

Issue

let myFilter = myContract.MyEvent({ fromBlock: x, toBlock: y }) doesn't work as both properties stay undefined when I inspect myFilter.

According to this issue it should work.

Steps to Reproduce

Setup a filter of your choice and try to set options 'fromBlock' and 'toBlock'. Example:

let myFilter = myContractInstance.MyEvent({
  fromBlock: 0,
  toBlock: 100
}).get((error, logs) => {
    if (error) console.log(error)

    console.log('logs:', logs.length)
    myFilter.stopWatching()
  })
})

Expected Behavior

Both properties should be set in myFilter.options and hence, the filter should return ALL occurrences of that event within the given blocks.

Actual Results

Both properties are undefined. The filter returns only the latest occurrence of that event.

Environment

cgewecke commented 6 years ago

@haggins We're migrating to Web3 1.0 with Truffle V5 and it looks the filter implementation there is more reliable - have had good luck with the .getPastEvents method and we have some tests and example usage for that here

You can install a pre-release of V5 by running:

npm install truffle@next

Usage notes are are available at #1129 (See the Web3 1.0 section). NB: Web3 1.0 comes with a few breaking changes.

Hope you don't mind but closing because we won't be making any further improvements to truffle-contract for V4 and this appears to work expected for V5.