Given a function and a event in a contract:
event OtherCreated(address other, address addr1, address addr2);
function doSomething(address addr1, address addr2){
if(aBool == true){
address other = new OtherContract(addr1, addr2);
others.push(other);
OtherCreated(other, addr1, addr2);
}
}
And given a js call in a browser:
.then(function(tx_id){
console.log('previous call completed');
otherCreated = contractAddr.OtherCreated();
otherCreated.watch(function(error, result){
if (!error)
{
console.log('in event handler');
}
return contractAddr.doSomething(account0, account1, {from: account0, gas: 4700000 });
})
The event handler is called twice. Is this an error on my part, or do I need to change something in this setup.
Output:
.then
part a success callback?contract.watch
is global, you don't have to use it with callback.