# 事件

事件在执行交易期间发出。每个 Move 模块都可以定义自己的事件，并选择在执行模块时何时发出事件。例如，在代币转账期间，发送方和接收方的帐户将分别发出 `SentEvent` 和 `Centevent`。这些数据存储在账本中，可以通过 REST 接口的 [Get 事件句柄](https://fullnode.devnet.aptoslabs.com/spec.html#/operations/get_events_by_event_handle)查询。

假设一个 `0xc40f1c9b9fdc204cf77f68c9bb7029b0abbe8ad9e5561f7794964076a4fbdcfd` 帐户向另一个帐户发送了代币，可以对 REST 接口进行以下查询：`https://fullnode.devnet.aptoslabs.com/accounts/c40f1c9b9fdc204cf77f68c9bb7029b0abbe8ad9e5561f7794964076a4fbdcfd/events/0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>/withdraw_events`。将输出存储在该帐户上所有的 `WithdrawEvent`，看起来是这样的：

```
[{
  "key":"0x0000000000000000caa60eb4a01756955ab9b2d1caca52ed",
  "sequence_number":"0",
  "type":"0x1::coin::WithdrawEvent",
  "data":{
    "amount":"1000"
  }
}]
```

每个注册事件都有一个独特的 `key`。密钥 `0x0000000000000000c40f1c9b9fdc204cf77f68c9bb7029b0abbe8ad9e5561f7794964076a4fbdcfd` 导向注册在帐户 `0xc40f1c9b9fdc204cf77f68c9bb7029b0abbe8ad9e5561f7794964076a4fbdcfd` 上的事件`0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>/sent_events`。可以使用此密钥直接进行事件查询，例如`https://fullnode.devnet.aptoslabs.com/events/0000000000000000c40f1c9b9fdc204cf77f68c9bb7029b0abbe8ad9e5561f7794964076a4fbdcfd`。

这些代表事件流，或事件列表，每个条目包含从`0` 开始的顺序增加的 `sequence_number`，一个 `type` 和 `data`。每个事件都必须由某种`type`来定义。可能有多个事件由相同或类似的`type`定义，特别是在使用泛型时。事件与`data`相关联。一般原则是包括所有必要的数据，以了解更改数据和事件的交易执行前后对基础资源的更改。


---

# 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://gushi10546.gitbook.io/aptos-kai-fa-zhe-wen-dang/gai-nian/shi-jian.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.
