This repository was archived by the owner on Mar 5, 2025. It is now read-only.
Undesired behaviour and unexpected error when toBlock
is passed to myContract.events.<eventName>
or myContract.events.allEvents
#3207
Labels
Intro
Right now if you want to use
myContract.events.<eventName>
ormyContract.events.allEvents
with the optiontoBlock
, which is not in the documentation, different fromlatest
. The call ends up in an undesired behaviour.If you set
fromBlock
different fromlatest
, aeth_getLogs
call will be done to get the past events fromfromBlock
tolatest
without usingtoBlock
-> Almost ok!. But later,fromBlock
is removed from the options and a subscription is made with{ fromBlock: undefined, toBlock: 100}
. Based on the subscribe implementation of go-ethereum, iffromBlock === null
(bacically, if it is not set), will setfromBLock
aslater
.This will finally check
fromBlock: 'latest'
andtoBlock: 100
returning, obviously, invalid from and to block combination: from > toExpected behavior
Throw an error saying that
toBlock
is not a valid option.Actual behavior
Error with
invalid from and to block combination: from > to
which is not an error from web3. But a go-ethereum oneSteps to reproduce the behavior
myContract.events.MyEvent({ fromBlock: 0, toBlock: 'latest' })
ormyContract.events.allEvents({ fromBlock: 0, toBlock: '100' })
Versions
Web3.js 1.X
Thanks @fmiras for the heads up.
The text was updated successfully, but these errors were encountered: