To get event logs of the past, you can instantiate the event with a block range, and use the myEvent.get
function to retrieve events.
In your example, we could do something minimal like this:
let transferEvent = product.Transferred({}, {fromBlock: 0, toBlock: 'latest'})
transferEvent.get((error, logs) => {
// we have the logs, now print them
logs.forEach(log => console.log(log.args))
})
Note: The first argument {}
can be used like a filter, to only catch certain events.
Above code logs this to console:
{ from: '0xc7d748654199d3594239a244d806e51331ca14b5',
to: '0x3c11b23b4d5adb2d534d262cf83cee773c9b1c0a',
quantity: { [String: '1'] s: 1, e: 0, c: [ 1 ] } }
{ from: '0xc7d748654199d3594239a244d806e51331ca14b5',
to: '0x3c11b23b4d5adb2d534d262cf83cee773c9b1c0a',
quantity: { [String: '3'] s: 1, e: 0, c: [ 3 ] } }
What about for all events of a contract?
Here the event instantiation would just look like this (notice we only use one parameter here):
let events = product.allEvents({fromBlock: 0, toBlock: 'latest'})
And then continue as before, with events.get()
.
event.get() vs event.watch()
event.watch()
is used for dealing with new events that fit a filter, as they stream in ("watching" the blockchain).
event.get()
is for grabbing existing events that fit some filter.
Sources:
Best Answer
You can't really console log with solidity, and truffle sometimes won't help much about understanding where your code fails.
Truffle indicates somes issues and warnings (like unused declared vars) but, as you mentionned, when using inheritance it can be a pain.
An easy way to deal with this, the one i use, is to load or copy/paste the .sol files into the remix IDE and check what are the issues it shows.
Once done and issues fixed i move my fixed code into the relevant files.
Note that you can download Remix IDE and create your own instance of it here
It might not be the perfect solution but awaiting for truffle to provide more information when having some issues, remix IDE is a very good tool for debugging. On my side i use truffle only for compiling and rely on the IDE for debugging.