# How can I read log/events that have been triggered in the past?

I have a smart contract with an event.

    event NewContractCreated(address _callerAddress, address _newContractAddress);


I know how to actively listen for new events:

var newContractEvent = myContract.NewContractCreated();
newContractEvent.watch(function(error, result){
if (!error){
console.log("Success");
}
});


That works just fine for me. But my question is: how do I listen for and pull the exact same data for events that happened before I started watching?

I tried the exact same thing but using get instead of watch... it half worked. It printed the top line "Success" but did not print the rest of the log lines.

You should be able to specify the period (in block no) to watch. According the documentation here

fromBlock: Number|String - The number of the earliest block (latest may be given to mean the most recent and pending currently mining, block). By default latest.

toBlock: Number|String - The number of the latest block (latest may be given to mean the most recent and pending currently mining, block). By default latest.

In your case, that should work :

var newContractEvent = myContract.NewContractCreated();
newContractEvent.watch({fromBlock: 0, toBlock: 'latest'}, function(error, result){
if (!error){
console.log("Success");
}
});


Try

var newContractEvent = myContract.NewContractCreated({}, {fromBlock: 12345, toBlock: 'latest'});
newContractEvent.watch(function(error, result) {
if (!error){
console.log("Success");