-
Notifications
You must be signed in to change notification settings - Fork 66
Add autonomous smart contract documentation #346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Ben-Rey
wants to merge
3
commits into
main
Choose a base branch
from
doc-asc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 the need of 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 hidden or 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,104 @@ | ||
--- | ||
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 | ||
|
||
:::note | ||
Find more information about autonomous smart contracts in the [Massa documentation](https://docs.massa.net/docs/learn/architecture/basic-concepts#autonomous-smart-contract-execution). | ||
::: | ||
|
||
## 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.