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");
contract.getPastEvents("allEvents").then(console.log);
Any ideas? Thanks!
Best Answer
Add a filter to the call with fromblock > 0: