I am monitoring the events when calling a method from my contract and want to save the output of one of my custom events, to display it.
The call of my method looks like this:
contract.tx
.method({ storageDepositLimit, gasLimit }, account , 'root', label)
.signAndSend(alice, ({events = [], status}) => {
if (status.isInBlock) {
console.log('in a block')
events.forEach(({ event, phase }) => {
if(api.events.contracts.ContractEmitted.is(event)){
const [account_id, contract_evt] = event.data
const decoded = new Abi(abi).decodeEvent(contract_evt)
// This (decoded) is the information I want to save
}else{
console.log('\t', phase.toString(), `: ${event.section}.${event.method}`, event.data.toString())
}
});
} else if (status.isFinalized) {
console.log('finalized')
}
})
How can I save 'decoded' outside of the contract call to display the information later?