You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/quick-start/developers/lottery-game-smart-contract/index.md
+38Lines changed: 38 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1380,6 +1380,44 @@ Enter the required param <symbol>: ELF
1380
1380
Enter the required param <owner>: $WALLET_ADDRESS
1381
1381
```
1382
1382
1383
+
## Understanding Inter-Contract Calls in aelf
1384
+
1385
+
In this section, we'll explore how inter-contract calls work in the aelf blockchain using the lottery game example from the tutorial. This will help you understand how different smart contracts can interact to perform complex operations.
1386
+
1387
+
### 1. **Smart Contract Overview**
1388
+
-**Lottery Contract**: Manages the game, including buying tickets, drawing winners, and distributing prizes.
1389
+
-**Token Contract**: Handles the token transactions needed for buying lottery tickets.
1390
+
1391
+
### 2. **Ticket Purchase Process**
1392
+
-**Initiating Purchase**: When a user wants to buy a lottery ticket, they interact with the Lottery Contract.
1393
+
-**Token Transfer Requirement**: The Lottery Contract must verify that the user has enough tokens and transfer those tokens to the lottery’s account to complete the purchase.
1394
+
1395
+
### 3. **Initializing Contract Reference State**
1396
+
-**Setting Contract Address**: The Lottery Contract must first initialize its reference to the Token Contract by setting the correct contract address in its state.
1397
+
1398
+
### 4. **Making an Inter-Contract Call**
1399
+
-**Calling Token Contract**: The Lottery Contract needs to interact with the Token Contract to transfer tokens.
1400
+
-**Method Invocation**: It calls a method in the Token Contract, such as `Transfer`.
1401
+
-**Parameters**: The call includes details like the sender’s address, the recipient’s address (the lottery account), and the amount of tokens.
1402
+
-**Encoding and Sending**: The parameters are encoded into a transaction format and sent to the Token Contract.
1403
+
1404
+
### 5. **Processing in the Token Contract**
1405
+
-**Token Transfer**: The Token Contract processes the transfer request by deducting tokens from the user’s account and adding them to the lottery account.
1406
+
-**Return Response**: The Token Contract then returns a result indicating whether the transfer was successful or if it failed.
1407
+
1408
+
### 6. **Handling the Response**
1409
+
-**Lottery Contract’s Role**: Once the Lottery Contract receives the response from the Token Contract, it checks if the transfer was successful.
1410
+
-**Next Steps**: If successful, the Lottery Contract updates the user's lottery ticket entries and continues with the game logic.
1411
+
1412
+
### 7. **Authorization and Security**
1413
+
-**Permission Checks**: Ensures that the Lottery Contract is authorized to invoke methods in the Token Contract.
1414
+
-**Secure Transactions**: Ensures that token transfers are secure and correctly authorized.
1415
+
1416
+
### 8. **Error Handling**
1417
+
-**Failure Management**: If the token transfer fails (e.g., due to insufficient funds), the Lottery Contract handles the error by potentially reverting the transaction or notifying the user.
1418
+
1419
+
By following these steps, you can see how inter-contract calls in aelf allow different contracts to work together smoothly. This modular approach helps in building complex applications like a lottery game by ensuring secure and authorized interactions between contracts.
0 commit comments