I want to get all past events from a contract I deployed on the Ropsten network.

Contract is:

pragma solidity ^0.5.1;

contract SampleContract {
    uint storageData;

    event MamboNumberTwo(uint _value);
    event MamboNumberFive(uint _value);
    event MamboNumberString(string _value);

    function test(uint x, uint y, string memory s) public {
        emit MamboNumberTwo(x);
        emit MamboNumberFive(y);
        emit MamboNumberString(s);

It is deployed at 0xdd73A24Ef263D9bed42b0db60607F915194A7fbF, as you can see this contract has emitted nine events so far.
I would like to get them using web3's myContract.getPastEvents("allEvents"), but this returns a Promise resolving in an empty array, as though no event was emitted yet.

Full code:

web3 = new Web3(...) // Connect to Ropsten node via Websocket
var contract = new web3.eth.Contract([...], "0xdd73A24Ef263D9bed42b0db60607F915194A7fbF");

Any ideas? Thanks!


Add a filter to the call with fromblock > 0:

contract.getPastEvents("allEvents", { fromBlock: 1}).then(console.log);
  • This raises 'Error: Returned error: leveldb: not found'
    – DamiToma
    May 31 '19 at 10:36
  • I was working with web3-1.0.0beta34, works fine with beta55. Thanks.
    – DamiToma
    Jun 19 '19 at 7:50
  • Thanks, that's pretty counter-intuitive since web3 says it's optional...
    – whamsicore
    Jun 13 at 1:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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