diff --git a/docs/build/autonomous-smart-contract/intro.md b/docs/build/autonomous-smart-contract/intro.md new file mode 100644 index 000000000..726e1c97e --- /dev/null +++ b/docs/build/autonomous-smart-contract/intro.md @@ -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! diff --git a/docs/build/autonomous-smart-contract/send-message.md b/docs/build/autonomous-smart-contract/send-message.md new file mode 100644 index 000000000..309ac02b1 --- /dev/null +++ b/docs/build/autonomous-smart-contract/send-message.md @@ -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, + filterAddress: Address = new Address(), + filterKey: StaticArray = new StaticArray(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. diff --git a/docs/build/autonomous-smart-contract/with-guaranteed-execution.md b/docs/build/autonomous-smart-contract/with-guaranteed-execution.md new file mode 100644 index 000000000..28708f367 --- /dev/null +++ b/docs/build/autonomous-smart-contract/with-guaranteed-execution.md @@ -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! diff --git a/docs/build/smart-contract/_category_.json b/docs/build/smart-contract/_category_.json deleted file mode 100644 index ad2d09dc0..000000000 --- a/docs/build/smart-contract/_category_.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "position": 2, - "link": { - "type": "generated-index", - "description": "Punch line to do once everything else will be done for SC development." - } -} diff --git a/sidebars.js b/sidebars.js index 6f085de59..a396d6868 100644 --- a/sidebars.js +++ b/sidebars.js @@ -266,7 +266,28 @@ const sidebars = { }, { type: "category", - label: "Web3 v2", + label: "Autonomous Smart Contract", + items: [ + { + type: "doc", + id: "build/autonomous-smart-contract/intro", + label: "Introduction", + }, + { + type: "doc", + id: "build/autonomous-smart-contract/send-message", + label: "Send Message", + }, + { + type: "doc", + id: "build/autonomous-smart-contract/with-guaranteed-execution", + label: "With Guaranteed Execution", + }, + ], + }, + { + type: "category", + label: "Massa-Web3", items: [ { type: "doc",