I have implement function in my solidity project and it log some event with event name 'NewRound' that I want to get value from it to save in my centralize database after I send transaction I got receipt look like this.
{
blockHash: '0x8df078a04e47cbe4ea7e58626ffc894f0d7b2620e821f9432aa1c03b3431d480',
blockNumber: 19125457,
contractAddress: null,
cumulativeGasUsed: 995561,
from: '0x0c46c078196461b17f7e1e652004bd7ee448ed49',
gasUsed: 116384,
logs: [
{
address: '0xc032d238fd4deD8A8AB97a8983AE3B51ccfa8fd3',
topics: [Array],
data: '0x',
blockNumber: 19125457,
transactionHash: '0x1e13744ddaf81cb3ca7a9cbd98ca6b2ede51a22d7e2795305b2621d59a0b9ac1',
transactionIndex: 5,
blockHash: '0x8df078a04e47cbe4ea7e58626ffc894f0d7b2620e821f9432aa1c03b3431d480',
logIndex: 7,
removed: false,
id: 'log_301e03cb'
}
],
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000040000800000000020000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000',
status: true,
to: '0xc032d238fd4ded8a8ab97a8983ae3b51ccfa8fd3',
transactionHash: '0x1e13744ddaf81cb3ca7a9cbd98ca6b2ede51a22d7e2795305b2621d59a0b9ac1',
transactionIndex: 5,
type: '0x0'
}
My log data is in topics params.But I have no idea how to decode it.Has anyone ever do something like this ?
The
topics[0]
field always stores the event signature hash. It's a keccak-256 hash of the event name, followed by parameter datatypes in parentheses.In your case, that's hash of the string
NewRound(uint256)
.Following items of the
topics
array are indexed parameters of the event. And the lasttopics
item is all unindexed parameters concatenated (which doesn't apply to your case, as there are no unindexed parameters).These items are ABI encoded and represented in hex.
Assuming you have the ABI JSON of the contract that emitted the event, you can decode the values using the web3.eth.abi.decodeLog() function.