I have configured a private blockchain with some solidity smartcontract inside a docker container on my AWS VPS.

When I connect to the blockchain with truffle console --network besu and test the smartcontract I deployed, everything works. But if I try to access all the events of a contract, I have to wait about 4 hours to get a result.

I have checked my server resources and it is not overloaded at all.

Here is my command :

let conf = await MyContract.deployed()
let events = await conf.getPastEvents('DepositAccessed', {fromBlock: 0, toBlock: 'latest'})

And here is the return after a very long wait :

[ { logIndex: 0,
    removed: false,
    blockNumber: 6543160,
    transactionIndex: 0,
    address: '0x8E006F61146d1893eea90085560DE387b8C837FE',
    id: 'log_c00bef65',
     Result {
       '0': '1',
       '1': '1648656287',
       '2': '1648830887',
       '3': '0x88C54eBE0DafEB9753b3c49Fc3106861d7e3Ff71',
       '4': '0x83d81Ee471e03Eb5DC08A91A38B70A8a6FC52af7',
       id: '1',
       startDate: '1648656287',
       endDate: '1648830887',
       beneficiary: '0x88C54eBE0DafEB9753b3c49Fc3106861d7e3Ff71',
       validatedBy: '0x83d81Ee471e03Eb5DC08A91A38B70A8a6FC52af7' },
    event: 'DepositAccessed',
     { data:
       topics: [Array] },
     Result {
       '0': <BN: 1>,
       '1': <BN: 62447f9f>,
       '2': <BN: 624729a7>,
       '3': '0x88C54eBE0DafEB9753b3c49Fc3106861d7e3Ff71',
       '4': '0x83d81Ee471e03Eb5DC08A91A38B70A8a6FC52af7',
       __length__: 5,
       id: <BN: 1>,
       startDate: <BN: 62447f9f>,
       endDate: <BN: 624729a7>,
       beneficiary: '0x88C54eBE0DafEB9753b3c49Fc3106861d7e3Ff71',
       validatedBy: '0x83d81Ee471e03Eb5DC08A91A38B70A8a6FC52af7' } } ]

The same function works perfectly and instantly when I am in my localhost network on my computer.

Do you know why it takes so long to make this simple request?

1 Answer 1


{fromBlock: 0, toBlock: 'latest'}

It iterates all the blocks on the network from 0 to now to find the events and this why it takes too long. On your local network there are no many blocks to iterate.

The best way to get and index events is using the Graph. If you cannot use it for some reason then you can change fromBlock to the block number where the contract is created (deployed) because before that block there is no events. This will reduce the time but it will get slower and slower each day.

  • Thanks for answering Majd, I will look into this solution.
    – Olfactoriz
    Apr 5, 2022 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.