Event Log
Event Log is one of the most crucial features of Pollux Virtual Machine (PVM), which is employed to output specific binary data and document it in TransactionInfo while PVM is executing a contract. The Event Log proves invaluable for developers in confirming, inspecting, and swiftly retrieving specific states of a smart contract. This article introduces the fundamentals of the Event mechanism and elucidates how to decode the Event Log.
Certainly! Here's a concise explanation based on your provided points:
The
Transfer
event is defined with three parameters:from
indicates the sender's address.to
indicates the receiver's address.value
indicates the transfer amount.
The statement
emit Transfer(msg.sender, toAddress, amount)
specifies triggering the correspondingTransfer
event after the transfer is completed. The event captures the sender's address, receiver's address, and the transfer amount.
Note: In adherence to Solidity conventions, the event name, such as Transfer
, is typically capitalized to distinguish it from corresponding functions like transfer
.
LOG
Solidity utilizes the LOG instruction to record event information in TransactionInfo. The details of the event are stored in the log field of TransactionInfo. The following example uses a TransactionInfo obtained through the gettransactioninfobyid API to illustrate the structure of an event.
Check the Event log along with the ABI to decode the data:
topics[0]
:ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef
represents the event itself, and the value is the result of the keccak256('Transfer(address,address,uint256)'). Therefore, the event is a Transfer event. The keccak256 hash value of the event can be calculated using POXweb.sha3(). Note: Ensure the keccak256 parameter is a string without spaces to maintain consistency in the calculated hash value.topics[1]
:00000000000000000000000079309abcff2cf531070ca9222a1f72c4a5136874
denotes the first indexed parameter, 'from'. The address provided is a 20-byte address with the removed '0x37' prefix. To obtain the POX HEX format address, take the last 40 bits of data and add '37' in front.topics[2]
:00000000000000000000000081b64b1c09d448d25c9eeb3ee3b8f3348a694c96
signifies the second indexed parameter, 'to' (recipient account address). The parsing follows the same procedure as mentioned above.data
:00000000000000000000000000000000000000000000000000000000b2d05e00
represents the value of a non-indexed parameter. If multiple non-indexed parameters exist, they should be listed in order based on the ABI coding rules. In this instance, there is only one non-indexed parameter, 'value,' which indicates the transfer amount. Convert the hexadecimal data to decimal.
Last updated