docs
Search…
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:
1
"events": [
2
...
3
]
Copied!
You can also see events in transaction logs in block explorer.

VM related events

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 lcs.
      data - lcs encoded data in hex. It could be decoded using lcs.
The data field always using LCS encoding (Libra Canonical Serialization). There is a community description of how it works. Also, Golang library, 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 Account module.
Events example:
1
[
2
{
3
"type":"vm.contract_events",
4
"attributes":[
5
{
6
"key":"sender_address",
7
"value":"wallet1qjgqxwk55p9ejlupmeza0r02hyextys9rrthgg"
8
},
9
{
10
"key":"source",
11
"value":"0x1::Account"
12
},
13
{
14
"key":"type",
15
"value":"0x1::Account::SentPaymentEvent"
16
},
17
{
18
"key":"data",
19
"value":"4d01000000000000000000000000000003646669db4b0ed53d2fd0a74ce8f0d106e7ab144eb0fbab00"
20
},
21
{
22
"key":"sender_address",
23
"value":"wallet1qjgqxwk55p9ejlupmeza0r02hyextys9rrthgg"
24
},
25
{
26
"key":"source",
27
"value":"0x1::Account"
28
},
29
{
30
"key":"type",
31
"value":"0x1::Account::ReceivedPaymentEvent"
32
},
33
{
34
"key":"data",
35
"value":"4d010000000000000000000000000000036466690490033ad4a04b997f81de45d78deab93265920500"
36
},
37
{
38
"key":"sender_address",
39
"value":"wallet1qjgqxwk55p9ejlupmeza0r02hyextys9rrthgg"
40
},
41
{
42
"key":"source",
43
"value":"script"
44
},
45
{
46
"key":"type",
47
"value":"u64"
48
},
49
{
50
"key":"data",
51
"value":"0a00000000000000"
52
}
53
]
54
},
55
{
56
"type":"vm.contract_status",
57
"attributes":[
58
{
59
"key":"status",
60
"value":"keep"
61
}
62
]
63
},
64
{
65
"type":"message",
66
"attributes":[
67
{
68
"key":"action",
69
"value":"execute_script"
70
},
71
{
72
"key":"sender",
73
"value":"wallet1qjgqxwk55p9ejlupmeza0r02hyextys9rrthgg"
74
}
75
]
76
},
77
{
78
"type":"transfer",
79
"attributes":[
80
{
81
"key":"recipient",
82
"value":"wallet17xpfvakm2amg962yls6f84z3kell8c5la07d0l"
83
},
84
{
85
"key":"amount",
86
"value":"1xfi"
87
}
88
]
89
}
90
]
Copied!
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:
1
https://rest.dfinance.co/txs?vm.contract_events.source=0x1::Account
Copied!
Also, look at our swagger and Dnode events doc for details.
Last modified 9mo ago
Copy link