There is a build in function to listen all the events in one watch statement
var events = myContractInstance.allEvents([additionalFilterObject]);
// watch for changes
events.watch(function(error, result){
if (!error)
console.log(result);
});
additionalFilterObject
can used to filter the results; example adding an address would be {address: myAddress}
On the other hand doesn't seems possible to filter the events using the names unless you specify the topics on the additionalFilterObject
where the topic addresses are the event/function hash (keccak256 of your event name eg. keccak256('EventName1(uint)')
) then you would have something like:
var events = myContractInstance.allEvents({address: myAddress, topics: [['0x1234...', '0x5678...']]});
// watch for changes
events.watch(function(error, result){
if (!error)
console.log(result);
});
but you can check the event result and filter the event name according to the events you want to listen:
var events = myContractInstance.allEvents([additionalFilterObject]);
// watch for changes
events.watch(function(error, result){
if (!error) {
if(['EventName1', 'EventName2'].includes(result.event)) {
//do
}
}
});
and that would be more readable maybe. Another less elegant solution could be
var event1 = contract.EventName1({from: address});
var event2 = contract.EventName2({from: address});
event1.watch(myCallback);
event2.watch(myCallback);
function myCallback(err, result) {
}