Events

Each transaction processed by dfinance blockchain can have events.

You can see them by querying transaction by id, they're stored under 'events' key:

"events": [
    ...
]

You can also see events in transaction logs in block explorerarrow-up-right.

For smart contracts related transactions, there are reserved types for events, such as:

  • contract_status - contains contract execution status. Usually contains "status" attribute, which represents one of the possible statuses:

    • "keep" - when transaction successful executed by VM (means passed pre-verification, byte code, arguments, etc).

    • "discard" - when transaction contains an error, contains attributes:

      • major_status - the major status of error, integer.

      • sub_status - the sub status of error, integer, optional.

      • message - text message, optional.

  • contract_events - contains events generated during smart contract execution. In our example of the script, we generated such an event using Event::emit. Contains next attributes (attributes always sorted in the same sequence):

    • sender_address - address of account which sent transaction that sent event.

    • source - the place where the event was sent, it could be script (in case it sent from user script), or path to module which sent event, e.g.: 0x1::Account.

    • type - contains data type, similar to contract arguments, but also could be a struct (in such case there will be reference to which indeed struct used in the event). A struct could be decoded using lcsarrow-up-right.

    • data - lcsarrow-up-right encoded data in hex. It could be decoded using lcsarrow-up-right.

The data field always using LCS encoding (Libra Canonical Serialization). There is a community descriptionarrow-up-right of how it works. Also, Golang libraryarrow-up-right, where you can see examples and use for your own projects. So decoding of the "data" field should happen with LCS.

There are two reserved events: sent and received events that fire when withdrawing or depositing of resources happens. The implementation you can found in the standard library in Accountarrow-up-right module.

Events example:

Events attributes always sorted in the same sequence, so you can go over contract_events attributes to parse event objects.

To catch events you can use REST API, for example, all events from Account module, look at this URL to see how filters work:

Also, look at our swaggerarrow-up-right and Dnode events docarrow-up-right for details.

Last updated

Was this helpful?