I have a flow which yields 4 events.
When I obtain the transaction hash via web3.js, I can see that all 4 events are included in the receipt logs, but only the last 2 events are in the decoded logs (which means I have to decode the first 2 events myself):
{
"receipt": {
...
"logs": [
{
"logIndex": 0,
...
},
{
"logIndex": 1,
...
},
{
"logIndex": 2,
...
},
{
"logIndex": 3,
...
}
],
...
},
"logs": [
{
"logIndex": 2,
...
},
{
"logIndex": 3,
...
}
]
}
What is the reason for this?
Best Answer
OK, I understand the reason:
All the events generated during the execution of the function called by web3 are included in the receipt logs, but only the events generated in the scope of the contract in which the function is implemented are included in the decoded logs.
For example, given the following on-chain code:
File
IContract1.sol
:File
Contract1.sol
:File
Contract2.sol
:If I execute the following off-chain code:
Then
hash.receipt.logs
will include bothEvent1
andEvent2
.But
hash.logs
will include onlyEvent2
.