I want to get events from block X. I have:
quorum-v2.4.0
web3js 1.2.6
And I have my own smart contracts I want to listen for. So I have created listener for allEvents like this:
const event = contract.events.allEvents({
fromBlock: 0,
});
And I also have following snippet of code where I am listening for the new events and also for the previous events. So I am specifying fromBlock
as described in web3js documentation:
fromBlock - Number|String|BN|BigNumber (optional): The block number (greater than or equal to) from which to get events on. Pre-defined block numbers as "latest",
event
.on('data', console.log)
.on('error', eventError);
When I dont specify fromBlock: 0,
it doesnt return anything which is OK. When I set fromBlock to 0 it always return the last block (e.g block 6 - see below) even though there are more blocks before the block number 6:
Object {address: "0x9d13C6D3aFE1721BEef56B55D303B09E021E27ab", blockNumber: 6, transactionHash: "0x51f254852cc897d6d3e40041b3a3e5dd7ec9a5ebddd771d9…", transactionIndex: 0, blockHash: "0x0eaec149917f0517aa99042875313882aa57831b3d02aaf5…", …}
Based on the documentation I assume it should return all events from block number 0. So I should get events in block 0,1,2,3,4...latest.
Do I understand it correctly?
Do I need to set some configuration? I want to workaround contract.getPastEvents
and I want to set fromBlock
within the subscription in listener.
fromBlock
to 1.fromBlock
it doesnt return any event. However when I setfromBlock
to something smaller than currentlatest
block (let's say 10) it always return the previous one (in this example block 9). I also tried converting to hex withweb3.utils.toHex(<fromBlock>)
but it didnt help as wellcontract.events.allEvents
?websocket
provider for subscription in general. More details here github.com/ethereum/web3.js/issues/3389