With web3.js 0.20.6.
$ node
> var AllEvents = require('web3/lib/web3/allevents')
undefined
> var decodeEventsForContract = (C, tr) => {
const ae = new AllEvents(C._web3, C.abi, C.address);
// ae.decode mutates the args, so we deep copy
return JSON.parse(JSON.stringify(tr))
.logs
.filter(l => l.address === C.address)
.map(l => ae.decode(l));
}
undefined
> decodeEventsForContract(MyTokenContract, txreceipt);
[ { logIndex: 0,
transactionIndex: 0,
transactionHash: '0xbc68d5ddc391fab84cd633a77dbc815cbc42546a13de9d123f7a5b820faa3cb4',
blockHash: '0xb604998aa0b6bece492530c9cbab494349a31b18a34067f225e1b59613952051',
blockNumber: 21,
address: '0x345ca3e014aaf5dca488057592ee47305d9b3e10',
type: 'mined',
event: 'Transfer',
args:
{ from: '0x0000000000000000000000000000000000000000',
to: '0x627306090abab3a6e1400e9345bc60c78a8bef57',
value: [BigNumber] } },
{ logIndex: 1,
transactionIndex: 0,
transactionHash: '0xbc68d5ddc391fab84cd633a77dbc815cbc42546a13de9d123f7a5b820faa3cb4',
blockHash: '0xb604998aa0b6bece492530c9cbab494349a31b18a34067f225e1b59613952051',
blockNumber: 21,
address: '0x345ca3e014aaf5dca488057592ee47305d9b3e10',
type: 'mined',
event: 'Mint',
args:
{ to: '0x627306090abab3a6e1400e9345bc60c78a8bef57',
value: [BigNumber],
minter: '0x627306090abab3a6e1400e9345bc60c78a8bef57' } } ]