# 事件（Events）

在事务执行期间发出事件。 每个 Move 模块都可以定义自己的事件，并选择在执行模块时何时发出事件。 例如，在一次 [代币转账](https://github.com/aptos-labs/aptos-core/blob/5d80b0d5fe09dbbf3e190459cdc376e8333ad6a3/aptos-move/framework/aptos-framework/sources/TestCoin.move#L152) 中，发送方和接收方的账户都会分别发出 `SentEvent` 和 `ReceivedEvent`。 这些数据存储在账本中，可以通过 REST 接口的 [Get events by event handle](https://fullnode.devnet.aptoslabs.com/spec.html#/operations/get_events_by_event_handle) 进行查询。

假设账户 `0xcaa60eb4a01756955ab9b2d1caca52ed` 向另一个账户发送了代币，可以对 REST 接口进行以下查询：`https://fullnode.devnet.aptoslabs.com/accounts/caa60eb4a01756955ab9b2d1caca52ed/events/0x1::TestCoin::TransferEvents/sent_events`。输出将是存储在该帐户上的所有 SentEvents，如下所示：

```json
[{
  "key":"0x0000000000000000caa60eb4a01756955ab9b2d1caca52ed",
  "sequence_number":"0",
  "type":"0x1::TestCoin::SentEvent",
  "data":{
    "amount":"1000",
    "to":"0xaabcd0d03bd1e135ccf806a652c5831f"
  }
}]
```

每个注册的事件都有一个唯一的 `key`。 这个 key `0x0000000000000000caa60eb4a01756955ab9b2d1caca52ed` 映射到在帐户 `0xcaa60eb4a01756955ab9b2d1caca52ed` 上注册的事件 `0x1::TestCoin::TransferEvents/sent_events`。 然后可以使用此密钥直接进行事件查询，例如 `https://fullnode.devnet.aptoslabs.com/events/0000000000000000caa60eb4a01756955ab9b2d1caca52ed`。

这些代表事件流，或事件列表，其中每个条目包含从 0 开始的顺序增加的序列号、类型和数据。 每个事件必须由某种类型定义。 可能存在由相同或相似类型定义的多个事件，尤其是在使用泛型时。 事件具有关联的数据。 一般原则是包含所有必要的数据，以了解在执行更改数据并发出事件的事务之前和之后对底层资源的更改。


---

# 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://wiki.aptos.movemove.org/ji-chu/shi-jian-events.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.
