Skip to content

Commit

Permalink
Update Doc “quick-start/hello-world/index”
Browse files Browse the repository at this point in the history
  • Loading branch information
vasmohi committed Jul 4, 2024
1 parent 878e965 commit c3681d1
Showing 1 changed file with 66 additions and 12 deletions.
78 changes: 66 additions & 12 deletions docs/quick-start/hello-world/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ This guide provides step-by-step instructions to set up your local development e

### Install Required Packages

* [Install dotnet](https://dotnet.microsoft.com/en-us/download)
* [Install dotnet](https://dotnet.microsoft.com/en-us/download/dotnet/6.0)
* Install aelf contract templates

```bash
dotnet new install AELF.ContractTemplates
dotnet new --install AELF.ContractTemplates
```

AELF.ContractTemplates contains various predefined templates for the ease of developing smart contracts on the aelf blockchain.
Expand All @@ -38,10 +38,8 @@ Please remember to export PATH after installing aelf.deploy.
* [Install Node.js](https://nodejs.org/en)
* Install aelf-command

### Install aelf-command

```bash
npm i -g aelf-command
sudo npm i -g aelf-command
```

aelf-command is a CLI tool for interacting with the aelf blockchain, enabling tasks like creating wallets and managing transactions.
Expand Down Expand Up @@ -74,13 +72,15 @@ curl -O --output-dir $ACS_DIR https://raw.githubusercontent.com/AElfProject/AElf

### Adding Your Smart Contract Code

Now that we have a template hello world project, we can customize the template to incorporate our own contract logic.
Now that we have a template hello world project, we can customise the template to incorporate our own contract logic.
Lets start by implementing methods to provide basic functionality for updating and reading a message stored persistently in the contract state.

```bash
cd src
```

The implementation of file `src/HelloWorldState.cs` is as follows:

```csharp
using AElf.Sdk.CSharp.State;

Expand Down Expand Up @@ -142,28 +142,82 @@ dotnet build

#### Create A Wallet

import CreateWallet from '@site/docs/_create-wallet.md';
To send transactions on the aelf blockchain, you must have a wallet.

Run this command to create aelf wallet.

<CreateWallet/>
```bash title="Terminal"
aelf-command create
```

![result](/img/create_wallet_output.png)

#### Acquire Testnet Tokens for Development

import GetTestnetToken from '@site/docs/_get-testnet-token.md';
To deploy smart contracts or execute on-chain transactions on aelf, you'll require testnet ELF tokens.

**Get ELF Tokens**

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<Tabs>
<TabItem value="cli" label="CLI" default>

Run the following command to get testnet ELF tokens from faucet. Remember to either export your wallet address and wallet password or replace $WALLET_ADDRESS and $WALLET_ADDRESS with your wallet address and wallet password respectively.

```bash title="Terminal"
export WALLET_ADDRESS="YOUR_WALLET_ADDRESS"
curl -X POST "https://faucet.aelf.dev/api/claim?walletAddress=$WALLET_ADDRESS" -H "accept: application/json" -d ""
```
To check your wallet's current ELF balance:
```bash title="Terminal"
export WALLET_PASSWORD="YOUR_WALLET_PASSWORD"
aelf-command call ASh2Wt7nSEmYqnGxPPzp4pnVDU4uhj1XW9Se5VeZcX2UDdyjx -a $WALLET_ADDRESS -p $WALLET_PASSWORD -e https://tdvw-test-node.aelf.io GetBalance
```
You will be prompted for the following:

```sh
Enter the required param <symbol>: **ELF**
Enter the required param <owner>: **$WALLET_ADDRESS**
```

You should see the Result displaying your wallet's ELF balance.

</TabItem>
<TabItem value="web" label="Web" default>

Go to this url [https://faucet-ui.aelf.dev](https://faucet-ui.aelf.dev). Enter your address and click `Get Tokens`.

<GetTestnetToken/>
![result](/img/get-token-ui.png)

</TabItem>
</Tabs>

### Deploy Your Smart Contract

import DeploySmartContract from '@site/docs/_deploy-smart-contract.md';
The smart contract needs to be deployed on the chain before users can interact with it.

Run the following command to deploy a contract. Remember to export the path of HelloWorld.dll.patched to CONTRACT_PATH.
Remember to export CONTRACT_FILE equals to HelloWorld.

```bash title="Terminal"
export CONTRACT_PATH="SRC_DIRECTORY_PATH" + /bin/Debug/net6.0
export CONTRACT_FILE=HelloWorld
aelf-deploy -a $WALLET_ADDRESS -p $WALLET_PASSWORD -c $CONTRACT_PATH/$CONTRACT_FILE.dll.patched -e https://tdvw-test-node.aelf.io/
```

Please wait for approximately 1 to 2 minutes. If the deployment is successful, it will provide you with the contract address.

<DeploySmartContract/>
![result](/img/deploy-result.png)

## 4. Interact with Your Deployed Smart Contract

Lets try to call methods on your newly-deployed smart contract using `aelf-command`.

Firstly, we will set a message using the `Update` method. Run the following command,
and enter the message argument as `test`. This will set `test` into the Message contract state.
Remember to export CONTRACT_ADDRESS equals to your deployed contract address.

```bash
aelf-command send $CONTRACT_ADDRESS -a $WALLET_ADDRESS -p $WALLET_PASSWORD -e https://tdvw-test-node.aelf.io Update
Expand Down

0 comments on commit c3681d1

Please sign in to comment.