-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add autonomous smart contract documentation
- Loading branch information
Showing
5 changed files
with
173 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
sidebar_position: 1 | ||
--- | ||
|
||
# Autonomous Smart Contracts: Introduction | ||
|
||
Autonomous Smart Contracts (ASCs) represent a revolutionary concept in blockchain technology, enabling smart contracts to operate independently without constant external triggers. This capability is a cornerstone feature of the Massa blockchain, setting it apart from traditional blockchain platforms. | ||
|
||
## Key Features | ||
|
||
1. **Self-Execution**: ASCs can schedule their own future executions. | ||
2. **Inter-Contract Communication**: ASCs can trigger functions in other contracts. | ||
3. **Conditional Execution**: Executions can be based on specific blockchain conditions. | ||
|
||
## Looking Ahead | ||
|
||
In the following sections, we'll explore how to implement Autonomous Smart Contracts using Massa's `sendMessage` function and discuss the upcoming feature of guaranteed execution for even more reliable autonomous operations. | ||
|
||
Stay tuned to learn how you can leverage these powerful capabilities in your Massa blockchain projects! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
--- | ||
id: send-message | ||
sidebar_label: Send Message | ||
--- | ||
|
||
# Autonomous Smart Contracts: Send Message | ||
|
||
The `sendMessage` function is one of the core mechanism enabling Autonomous Smart Contracts (ASCs) in the Massa blockchain. This powerful feature allows contracts to schedule future executions, creating truly autonomous systems. | ||
|
||
## Understanding `sendMessage` | ||
|
||
### Function Signature | ||
|
||
```typescript | ||
function sendMessage( | ||
at: Address, | ||
functionName: string, | ||
validityStartPeriod: u64, | ||
validityStartThread: u8, | ||
validityEndPeriod: u64, | ||
validityEndThread: u8, | ||
maxGas: u64, | ||
rawFee: u64, | ||
coins: u64, | ||
functionParams: StaticArray<u8>, | ||
filterAddress: Address = new Address(), | ||
filterKey: StaticArray<u8> = new StaticArray<u8>(0) | ||
): void; | ||
``` | ||
|
||
### Key Parameters | ||
|
||
- `at`: The target contract address | ||
- `functionName`: The function to be called | ||
- `validityStartPeriod` & `validityEndPeriod`: The time window for execution | ||
- `maxGas`: Maximum gas allowed for execution | ||
- `rawFee`: Fee for prioritizing the message | ||
- `filterAddress` & `filterKey`: Optional conditions for execution | ||
|
||
## Usage Patterns | ||
|
||
### Self-Calling Functions | ||
|
||
Create recursive processes: | ||
|
||
```typescript | ||
export function recursiveFunction(): void { | ||
if (shouldContinue()) { | ||
sendMessage( | ||
Context.callee(), // Current contract's address | ||
"recursiveFunction", // Function to call | ||
Context.currentPeriod(), // Start validity period | ||
Context.currentThread(), // Example start thread | ||
Context.currentPeriod() + 10, // Meaning 10 periods of validity | ||
Context.currentThread(), // Example end thread | ||
4_000_000_000, // Example maxGas | ||
100000, // Example rawFee | ||
0, // Example coins | ||
[] // Example functionParams | ||
); | ||
} | ||
} | ||
``` | ||
|
||
### Inter-Contract Communication | ||
|
||
Schedule calls to other contracts: | ||
|
||
```typescript | ||
export function scheduleExternalCall(): void { | ||
sendMessage( | ||
new Address("AS..."), // Other contract's address | ||
"externalFunction", | ||
Context.currentPeriod(), | ||
Context.currentThread(), | ||
Context.currentPeriod() + 10, | ||
Context.currentThread(), | ||
4_000_000_000, // maxGas | ||
100000, // rawFee | ||
0, // coins | ||
new Args().add("my_param").serialize() | ||
); | ||
} | ||
``` | ||
|
||
## Important Considerations | ||
|
||
### Execution Not Guaranteed | ||
|
||
The execution of scheduled messages depends on network conditions and the provided fee. Higher network traffic and lower fees may result in failed executions. | ||
|
||
### Best Practices | ||
|
||
1. Provide adequate fees, especially for critical operations | ||
2. Use appropriate validity periods to balance execution likelihood and timeliness | ||
3. Carefully manage contract state and handle potential race conditions | ||
|
||
## Conclusion | ||
|
||
The `sendMessage` function is a powerful tool for creating autonomous systems on Massa. While it offers great flexibility, developers must carefully consider execution dynamics and implement appropriate safeguards to ensure reliable operation of their Autonomous Smart Contracts. |
32 changes: 32 additions & 0 deletions
32
docs/build/autonomous-smart-contract/with-guaranteed-execution.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
id: with-guaranteed-execution | ||
sidebar_label: With Guaranteed Execution | ||
--- | ||
|
||
# Autonomous Smart Contracts: Guaranteed Execution | ||
|
||
## Introduction | ||
|
||
Massa is developing an exciting new feature for Autonomous Smart Contracts (ASCs) called Guaranteed Execution. This feature aims to enhance the reliability and predictability of smart contract operations on the Massa blockchain. | ||
|
||
## Concept Overview | ||
|
||
Guaranteed Execution introduces a mechanism for smart contracts to reserve future execution slots, ensuring that critical operations occur at specified times, regardless of network conditions. | ||
|
||
### Key Aspects | ||
|
||
1. **Future Slot Reservation**: Smart contracts can book specific future time slots for execution. | ||
2. **Execution Assurance**: Once reserved, the execution is guaranteed to occur at the specified time. | ||
3. **Resource Management**: The system allocates computational resources for these guaranteed executions. | ||
4. **Advance Planning**: Allows for scheduling executions further into the future with certainty. | ||
|
||
## Advantages Over Current System | ||
|
||
Guaranteed Execution addresses limitations in the current ASC system: | ||
|
||
- **Predictability**: Eliminates uncertainty about whether a transaction will be processed in high-congestion periods. | ||
- **Timeliness**: Ensures critical operations occur exactly when | ||
|
||
## Conclusion | ||
|
||
Guaranteed Execution is a significant step forward in the evolution of Autonomous Smart Contracts. This feature will provide developers with a powerful tool for building robust, reliable, and predictable smart contract systems. Stay tuned for more updates on this exciting development! |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters