APTOS concepts | Events

Events are generated during the execution of a transaction. Each Move module can define its own events and choose when to generate these events during module execution. For example, during a coin transfer, the sender and receiver accounts will generate SentEvent and ReceivedEvent respectively. This data is stored in the registry and can be queried through the Get events by event handle function of the REST interface.

Assuming that the account 0xc40f1c9b9fdc204cf77f68c9bb7029b0abbe8ad9e5561f7794964076a4fbdcfd sent coins to another account, we can make the following request to the REST interface: https://fullnode.devnet.aptoslabs.com/accounts/c40f1c9b9fdc204cf77f68c9bb7029b0abbe8ad9e5561f7794964076a4fbdcfd/events/0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>/withdraw_events. This will retrieve all the WithdrawEvents funds stored on that account, it will look like this

Enter fullscreen mode Exit fullscreen mode

Each registered event has a unique key. Ключ 0x0000000000000000c40f1c9b9fdc204cf77f68c9bb7029b0abbe8ad9e5561f7794964076a4fbdcfd отображает событие 0x1::coin::CoinStore<0x1: :aptos_coin: :AptosCoin>/sent_events registered to the account 0xc40f1c9b9fdc204cf77f68c9bb7029b0abbe8ad9e5561f7794964076a4fbdcfd. This key can then be used to directly query events, such as https://fullnode.devnet.aptoslabs.com/events/0000000000000000c40f1c9b9fdc204cf77f68c9bb7029b0abbe8ad9e5561f7794964076a4fbdcfd.

They are event streams, or a list of events, each entry of which contains a sequentially increasing number sequence_number starting with 0, type and data. Each event must be defined by some type. There can be multiple events defined with the same or similar type, especially when using generics. Events have associated data. The general principle is to include all data needed to understand the changes in the underlying resources before and after the transaction that changed the data and triggered the event.

Оцените статью
Добавить комментарий