Skip to content
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

Closed
nachomazzara opened this issue Nov 14, 2019 · 1 comment · Fixed by #3567
Labels
1.x 1.0 related issues Needs Clarification Requires additional input

Comments

@nachomazzara
Copy link
Contributor

Intro

Right now if you want to use myContract.events.<eventName> or myContract.events.allEvents with the option toBlock, which is not in the documentation, different from latest. The call ends up in an undesired behaviour.

If you set fromBlock different from latest, a eth_getLogs call will be done to get the past events from fromBlock to latest without using toBlock -> 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, if fromBlock === null (bacically, if it is not set), will set fromBLock as later.

This will finally check fromBlock: 'latest' and toBlock: 100 returning, obviously, invalid from and to block combination: from > to

Expected 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 one

Steps to reproduce the behavior

  1. Call myContract.events.MyEvent({ fromBlock: 0, toBlock: 'latest' }) or myContract.events.allEvents({ fromBlock: 0, toBlock: '100' })

Versions

Web3.js 1.X

Thanks @fmiras for the heads up.

@nachomazzara nachomazzara changed the title Undesired behaviour and unexpected error when toBlock is passed to to myContract.events.<eventName> or myContract.events.allEvents Undesired behaviour and unexpected error when toBlock is passed to myContract.events.<eventName> or myContract.events.allEvents Nov 14, 2019
@nivida nivida added 1.x 1.0 related issues Needs Clarification Requires additional input labels Nov 19, 2019
@wbt
Copy link
Contributor

wbt commented May 29, 2020

I am also seeing this error when using myContract.events.<eventName> with toBlock set to anything other than 'latest', even if the value is greater than fromBlock.

Got error back from event:  Error: Returned error: invalid from and to block combination: from > to
    at Object.ErrorResponse (my:\project\node_modules\@truffle\interface-adapter\node_modules\web3-core-helpers\src\errors.js:29:16)
    at Object.callback (my:\project\node_modules\@truffle\interface-adapter\node_modules\web3-core-requestmanager\src\index.js:140:36)
    at my:\project\node_modules\web3-providers-ws\src\index.js:133:41
    at Array.forEach (<anonymous>)
    at WebsocketProvider._onMessage (my:\project\node_modules\web3-providers-ws\src\index.js:118:69)
    at W3CWebSocket._dispatchEvent [as dispatchEvent] (my:\project\node_modules\yaeti\lib\EventTarget.js:115:12)
    at W3CWebSocket.onMessage (my:\project\node_modules\@web3-js\websocket\lib\W3CWebSocket.js:234:14)
    at WebSocketConnection.<anonymous> (my:\project\node_modules\@web3-js\websocket\lib\W3CWebSocket.js:205:19)
    at WebSocketConnection.emit (events.js:159:13)
    at WebSocketConnection.processFrame (my:\project\node_modules\@web3-js\websocket\lib\WebSocketConnection.js:554:26)
    at my:\project\node_modules\@web3-js\websocket\lib\WebSocketConnection.js:323:40
    at process._tickCallback (internal/pro5cess/next_tick.js:150:11)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1.x 1.0 related issues Needs Clarification Requires additional input
Projects
None yet
3 participants