I would like to get the result of a function by listening its emitted event. These are two pieces of code of my contrats
CONTRACT 1:
function createTradeableContract() public stopInEmergency returns(address subcontractAddr) {
TradeableContract tc = new TradeableContract(msg.sender);
contracts.push(tc);
return tc;
}
CONTRACT 2:
function TradeableContract (address ownerAddr) public {
owner = ownerAddr;
NewOwnerEvent(0x0,owner);
}
I am using web3.0 1.0 beta. I wrote this code. I cannot understand why I cannot see the event in the logs.
self.contractCreator.methods.createTradeableContract().send({from: selectedAccount})
.once('receipt', function(receipt){
console.log("receipt");
console.log(receipt);
console.log("eventos...");
console.log(receipt.logs); //it is undefined
})
.on('error', function(error){
console.log("erro");
console.log(error);
})
.then( receipt =>
{
console.log(receipt);
console.log("events...");
console.log(receipt.logs); //it is undefined
})
.catch (error => console.warn(error));
If I use Remix, I can see the event in the console (below).
[
{
"from": "0x8722aff990eda4d2d11915705076af5823f5f14c",
"topic": "0x09f86d61eb5d6904c1fa8e5f071f171ec90eccc6e0a7b61d563a7d693db815f6",
"event": "NewOwnerEvent",
"args": {
"0": "0x0000000000000000000000000000000000000000",
"1": "0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c",
"old": "0x0000000000000000000000000000000000000000",
"current": "0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c",
"length": 2
}
}
]
Since I cannot get the returned value of a function that change state, I am using events. But... What is the best way to get the emmited event after invoking the function?