# 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.

```
contract ExampleContractWithEvent {
    event Transfer(address indexed from, address indexed to, uint256 value);

    constructor() payable public {}

    function contractTransfer(address toAddress, uint256 amount) public {
        toAddress.transfer(amount);
        emit Transfer(msg.sender, toAddress, amount);
    }
}
```

Certainly! Here's a concise explanation based on your provided points:

1. 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.
2. The statement `emit Transfer(msg.sender, toAddress, amount)` specifies triggering the corresponding `Transfer` 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.

```
{
"anonymous": false,
"inputs": [
{"indexed": true, "name": "from", "type": "address"},
{"indexed": true, "name": "to", "type": "address"},
{"indexed": false, "name": "value", "type": "uint256"}
],
"name": "Transfer",
"type": "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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://pox-chain.gitbook.io/doc/pox-protocol/pox-virtual-machine-pvm/event-log.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
