...by Daniel Szego
quote
"On a long enough timeline we will all become Satoshi Nakamoto.."
Daniel Szego

Monday, January 29, 2018

Solidity and Truffle Tips and Tricks - all past events of a contract


So, if you want to read out all of the events of a contract and you have a geth client and a synchronized blockchain, even if you synchronized the blockchain with the --fast directive, you can use the following pattern: 

var abi = [{...}];

var contract= web3.eth.contract(abi);

var corionRef =contract.at(<... address...>);

corionRef.<Event>({},{fromBlock:0,toBlock: 'latest'}).get(
  function (error, eventResult) {
    if (error) console.log('Error in Event event handler: ' +
        error); 
    else console.log('Event result:'+ JSON.stringify(eventResult));
});