0

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,
    blockHash:
     '0xaf7025b17a4f93679d5f06fca2ee9e7301f04a2f62f57feee80c2008dcbf20b6',
    transactionHash:
     '0x0ac45c73ed69eb314c518d1b9b44bb2da90950845e25beef3ad5687e184a0229',
    transactionIndex: 0,
    address: '0x8E006F61146d1893eea90085560DE387b8C837FE',
    id: 'log_c00bef65',
    returnValues:
     Result {
       '0': '1',
       '1': '1648656287',
       '2': '1648830887',
       '3': '0x88C54eBE0DafEB9753b3c49Fc3106861d7e3Ff71',
       '4': '0x83d81Ee471e03Eb5DC08A91A38B70A8a6FC52af7',
       id: '1',
       startDate: '1648656287',
       endDate: '1648830887',
       beneficiary: '0x88C54eBE0DafEB9753b3c49Fc3106861d7e3Ff71',
       validatedBy: '0x83d81Ee471e03Eb5DC08A91A38B70A8a6FC52af7' },
    event: 'DepositAccessed',
    signature:
     '0xadc84df85695a185ad1dca61f1a45189ceba0c1b6ff1491138950e6efa92dae5',
    raw:
     { data:
        '0x0000000000000000000000000000000000000000000000000000000062447f9f00000000000000000000000000000000000000000000000000000000624729a700000000000000000000000088c54ebe0dafeb9753b3c49fc3106861d7e3ff7100000000000000000000000083d81ee471e03eb5dc08a91a38b70a8a6fc52af7',
       topics: [Array] },
    args:
     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

0

{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.

1
  • 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.