-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from AElfProject/feature/tutorials
feat: tutorials
- Loading branch information
Showing
28 changed files
with
3,837 additions
and
108 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
106 changes: 106 additions & 0 deletions
106
app/tutorials/[id]/_content/hello-world/hello-world.mdx
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,106 @@ | ||
# Hello World Contract | ||
|
||
**Description**: This is the simplest contract to get you started. It introduces the | ||
basic structure of a smart contract and shows how to deploy and interact with | ||
it. | ||
|
||
**Purpose**: To familiarize you with the basic syntax and deployment process of | ||
smart contracts on aelf blockchain. | ||
|
||
**Difficulty Level**: Easy | ||
|
||
## Step 1 - Adding Your Smart Contract Code | ||
|
||
First, generate the template: <GenerateTemplate />. | ||
|
||
We'll start by creating methods to update and read a message stored in the contract. | ||
|
||
The implementation of file `src/HelloWorldState.cs` is as follows: | ||
|
||
```csharp title="HelloWorldState.cs" | ||
using AElf.Sdk.CSharp.State; | ||
|
||
namespace AElf.Contracts.HelloWorld | ||
{ | ||
// The state class is access the blockchain state | ||
public class HelloWorldState : ContractState | ||
{ | ||
// A state that holds string value | ||
// highlight-next-line | ||
public StringState Message { get; set; } | ||
} | ||
} | ||
``` | ||
|
||
The implementation of file `src/HelloWorld.cs` is as follows: | ||
|
||
```csharp title="HelloWorld.cs" | ||
// contract implementation starts here | ||
namespace AElf.Contracts.HelloWorld | ||
{ | ||
public class HelloWorld : HelloWorldContainer.HelloWorldBase | ||
{ | ||
// A method that updates the contract state, Message with a user input | ||
// highlight-start | ||
public override Empty Update(StringValue input) | ||
{ | ||
State.Message.Value = input.Value; | ||
Context.Fire(new UpdatedMessage | ||
{ | ||
Value = input.Value | ||
}); | ||
return new Empty(); | ||
} | ||
|
||
// A method that reads the contract state, Message | ||
public override StringValue Read(Empty input) | ||
{ | ||
var value = State.Message.Value; | ||
return new StringValue | ||
{ | ||
Value = value | ||
}; | ||
} | ||
// highlight-end | ||
} | ||
} | ||
``` | ||
|
||
## Step 2 - Building Smart Contract | ||
|
||
Build the new code by clicking the Build button. | ||
|
||
## Step 3 - Deploy Smart Contract | ||
|
||
Deploy the new code by clicking the Deploy button. | ||
|
||
## 🎯 Conclusion | ||
|
||
#### 🎊 Congratulations! | ||
|
||
You've successfully completed the Hello World Contract tutorial! | ||
Awesome job sticking with it until the end. 🌟 | ||
|
||
#### 📚 What You've Learned | ||
|
||
In this tutorial, you've discovered: | ||
|
||
- 🛠️ How to set up your development environment for aelf. | ||
- 💻 The basics of writing a smart contract in C# for the aelf blockchain. | ||
- 🚀 How to deploy your Hello World Contract on the aelf network. | ||
|
||
#### 🔍 Final Output | ||
|
||
By now, you should have: | ||
|
||
- 📜 A deployed Hello World Contract on the aelf blockchain. | ||
|
||
To verify, you should have seen the **`test`** message returned when you called the Read method after setting it using the Update method. If you see this message, you've nailed it! 🏆 | ||
|
||
#### ➡️ What's Next? | ||
|
||
Now that you've got the basics down, why not dive into more advanced topics or other tutorials like the Lottery Game Contract or Voting Contract? | ||
|
||
Keep experimenting and building to level up your aelf blockchain development skills. 🚀 | ||
|
||
Happy coding! 😊 |
Oops, something went wrong.