I am trying to watch all events of a contract with many events. The following code is supposed to do just that:
var events = myContract.allEvents();
events.watch(function(error, event){
if (error) {
console.log("Error: " + error);
} else {
console.log('some event occured');
}
});
But if I try it in geth, and trigger an event, this is what the console tells me:
cannot find event for log
undefined: undefined
Can someone please tell me what s wrong with this code?
(I run mist at the same time, I just geth attached)
Note that I have no difficulty watching individual events. I am instead trying to watch them all with the code above.
Best Answer
How is
myContract
defined? Is there anallEvents()
event type?I will assume that you have defined the
myContract
variable but you are trying to useallEvents
to retrieve all events.See How do I retrieve the Voted events from The DAO for an example of how to retrieve specific events generated by a contract.
See web3.eth.filter to use the
filter(...)
function to retrieve all events.Update Responding To Comments Below
Here's a bit of code you to check out
web3.eth.filter(...)
with:The results produce include:
The events above are the Golem Network Token (GNT) TokenTraderFactory with source code available from 0xc4af56cd5254aef959d4bce2f75874007808b701. You can find further information on this TokenTraderFactory at Trustless Golem Network Token (GNT) Selling Contract.
Note that the topics in the events above include the hex strings below:
Here are the events declared in the TokenTraderFactory contract:
In
geth
:You will have to interpret the data fields by yourself. From the second listing above, the data is
0x2fd64880bc17977672b2e25fff32b433975c4004b4fbd094936429e92f58d39f0000000000000000000000000020dba1d308339182239056a00fcc146d2e26e0000000000000000000000000399156ee3339f4b29a53e307b98cce09fda3bac7
This can be separated into:
In the TokenTraderFactory
event TradeListing(bytes32 bookid, address owner, address addr)
event,