vechain / connex

The mono-repo contains libraries to help build dApps for VeChain.
https://docs.vechain.org/developer-resources/sdks-and-providers/connex
GNU Lesser General Public License v3.0
85 stars 3.6k forks source link

How to get the number of events emitted in the specific SC? #117

Closed LinSays closed 2 years ago

LinSays commented 2 years ago

HI. I want to fetch all events from specific block to the latest one using connex. According to the documentation, I have to implement like this:

const currentBlockStatus = connex.thor.status; const filter = mpEvents.filter([]).range({ unit: 'block', from: FromBlock, to:currentBlockStatus.head.number }); filter.apply(offset, limit).then(logs=>{ console.log(logs); })

I've set the offset as 0 to get the events from the Block - FromBlock. But the problem is limit. I just can't get the number of events emitted with this abi. I can only specific number(limit) of the events emitted in the SC. Is there any way to solve this issue? Thanks in advance

libotony commented 2 years ago

No option to get the count, but you can define a step iterating one by one til no outputs.

const step = 20
let offest = 0
for(;;){
    const outputs = await filter.apply(offset, step)
    if (outputs.length==0){
        break
    }
    offset += step
}