File tree Expand file tree Collapse file tree 2 files changed +55
-4
lines changed Expand file tree Collapse file tree 2 files changed +55
-4
lines changed Original file line number Diff line number Diff line change @@ -35,10 +35,8 @@ export default defineConfig({
35
35
{ text : 'Cheat Sheet' , link : '/smart-contracts/contract-cheat-sheet' } ,
36
36
{ text : 'Context' , link : '/smart-contracts/context' } ,
37
37
{ text : 'Functions' , link : '/smart-contracts/functions' } ,
38
- {
39
- text : 'Modules' ,
40
- collapsed : true ,
41
- items : [
38
+ { text : 'Events' , link : '/smart-contracts/events' } ,
39
+ { text : 'Modules' , collapsed : true , items : [
42
40
{ text : 'Crypto' , link : '/smart-contracts/modules/crypto-stdlib' } ,
43
41
{ text : 'Hashlib' , link : '/smart-contracts/modules/hashlib-stdlib' } ,
44
42
{ text : 'Random' , link : '/smart-contracts/modules/random-stdlib' } ,
Original file line number Diff line number Diff line change
1
+ LogEvents are used to track & index when your smart contract performs an operation.
2
+
3
+ Emitted events are automatically recorded & indexed by the ` Blockchain Data Service Node (BDS) ` & queryable via the
4
+
5
+ # Use-cases
6
+
7
+ In many situations in your app, you will want to track when something happens in your smart contract.
8
+
9
+ Here are some example situations when you may want to emit an event from your contract :
10
+
11
+ - When a swap occurs on a DEX.
12
+ - When an NFT is minted.
13
+ - When a transfer is received by a specific account.
14
+ - When a transfer is sent from a specific account.
15
+ - When an account approves tokens to be used by a smart contract.
16
+
17
+ # Usage
18
+
19
+ ### Smart Contract
20
+
21
+ ``` python
22
+ """
23
+ Declare the event at the top of the contract code.
24
+ """
25
+
26
+ TransferEvent = LogEvent(
27
+ event = " Transfer" ,
28
+ params = {
29
+ " from" : {' type' : str , ' idx' : True },
30
+ " to" : {' type' : str , ' idx' : True },
31
+ " amount" : {' type' : (int , float , decimal)}
32
+ }
33
+ )
34
+
35
+ """
36
+ At the end of the function in the operation you want to track,
37
+ call the event.
38
+ """
39
+
40
+ @export
41
+ def transfer (amount : float , to : str ):
42
+ ...
43
+ balances[ctx.caller] -= amount
44
+ balances[to] += amount
45
+
46
+ TransferEvent({
47
+ " from" : ctx.caller,
48
+ " to" : to,
49
+ " amount" : amount
50
+ })
51
+ ```
52
+
53
+ For info on how to query events, see the [ GraphQL] ( ../node/interfaces/graphql ) docs.
You can’t perform that action at this time.
0 commit comments