From 808ada510f021347de84b13f268f9e88d8b7a0e5 Mon Sep 17 00:00:00 2001 From: AelfHarsh Date: Fri, 5 Jul 2024 13:45:37 +0530 Subject: [PATCH] Changing folder for lotterybank --- .../deploy-interact-smart-contract.md | 133 ++++++++++++++++++ .../{index.md => develop-smart-contract.md} | 89 ++---------- .../lottery-game/setup-enviornment.md | 66 +++++++++ sidebars.ts | 29 +++- 4 files changed, 240 insertions(+), 77 deletions(-) create mode 100644 docs/tutorials/dapp-development/lottery-game/deploy-interact-smart-contract.md rename docs/tutorials/dapp-development/lottery-game/{index.md => develop-smart-contract.md} (94%) create mode 100644 docs/tutorials/dapp-development/lottery-game/setup-enviornment.md diff --git a/docs/tutorials/dapp-development/lottery-game/deploy-interact-smart-contract.md b/docs/tutorials/dapp-development/lottery-game/deploy-interact-smart-contract.md new file mode 100644 index 00000000..8aa78928 --- /dev/null +++ b/docs/tutorials/dapp-development/lottery-game/deploy-interact-smart-contract.md @@ -0,0 +1,133 @@ +--- +sidebar_position: 3 +title: Deploy Your Smart Contract +description: Deploying and Interacting with smartcontract +--- + +### Preparing for deployment + +#### Create A Wallet + +To send transactions on the aelf blockchain, you must have a wallet. + +Run this command to create aelf wallet. + +```bash +aelf-command create +``` + +![result](/img/create_wallet_output.png) + +#### Acquire Testnet Tokens(Faucet) for Development + +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'; + + + + +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 +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 +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 : ELF +Enter the required param : **$WALLET_ADDRESS** +``` + +You should see the result displaying your wallet's ELF balance. + + + + +Go to this url ``. Enter your address and click `Get Tokens`. + +![result](/img/get-token-ui.png) + + + + +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 LotteryGame.dll.patched to CONTRACT_PATH. For this you need to copy actual path src/bin/Debug/net6.0/LotteryGame.dll.patched of lottery-game directory. For example: + +```bash +export CONTRACT_PATH = /Users/mohit/Desktop/aelf/lottery-game/src/bin/Debug/net6.0/LotteryGame.dll.patched +``` + +```bash +export CONTRACT_PATH="SRC_DIRECTORY_PATH" + /bin/Debug/net6.0/LotteryGame.dll.patched +aelf-deploy -a $WALLET_ADDRESS -p $WALLET_PASSWORD -c $CONTRACT_PATH -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. + +![result](/img/deploy-result.png) + +## 4. Interact with Your Deployed Smart Contract + +### Approving Smart Contract Spending + +```bash +aelf-command send ASh2Wt7nSEmYqnGxPPzp4pnVDU4uhj1XW9Se5VeZcX2UDdyjx -a $WALLET_ADDRESS -p $WALLET_PASSWORD -e https://tdvw-test-node.aelf.io Approve +``` + +:::tip +ℹ️ Note: `ASh2Wt7nSEmYqnGxPPzp4pnVDU4uhj1XW9Se5VeZcX2UDdyjx` is the contract address of `Multitoken Contract` on aelf Testnet Sidechain (tDVW). +::: + +When prompted, enter the following parameters to approve the spending of 90 ELF tokens: + +```terminal +Enter the params one by one, type `Enter` to skip optional param: +? Enter the required param : $CONTRACT_ADDRESS +? Enter the required param : ELF +? Enter the required param : 9000000000 +``` + +### Initializing Lottery Game Contract + +```bash +aelf-command send $CONTRACT_ADDRESS -a $WALLET_ADDRESS -p $WALLET_PASSWORD -e https://tdvw-test-node.aelf.io Initialize +``` + +### Depositing funds into the Lottery Game Contract + +```bash +aelf-command send $CONTRACT_ADDRESS -a $WALLET_ADDRESS -p $WALLET_PASSWORD -e https://tdvw-test-node.aelf.io Deposit +``` + +### Playing the Lottery Game + +```bash +aelf-command send $CONTRACT_ADDRESS -a $WALLET_ADDRESS -p $WALLET_PASSWORD -e https://tdvw-test-node.aelf.io Play +``` + +Let's check the `balance` + +```bash +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: + +```terminal +Enter the required param : ELF +Enter the required param : $WALLET_ADDRESS +``` diff --git a/docs/tutorials/dapp-development/lottery-game/index.md b/docs/tutorials/dapp-development/lottery-game/develop-smart-contract.md similarity index 94% rename from docs/tutorials/dapp-development/lottery-game/index.md rename to docs/tutorials/dapp-development/lottery-game/develop-smart-contract.md index 5e96b356..772f661e 100644 --- a/docs/tutorials/dapp-development/lottery-game/index.md +++ b/docs/tutorials/dapp-development/lottery-game/develop-smart-contract.md @@ -1,74 +1,8 @@ --- -sidebar_position: 4 -title: Lottery Game Contract +sidebar_position: 2 +title: Develop the smart contract +description: Developing the smart contract --- -# Lottery Game Contract - -This guide provides step-by-step instructions to set up your local development environment to get started developing and deploying aelf smart contracts. - -## 1. Setup Environment - -### Prerequisites - - - - -* Basic knowledge of terminal commands -* **IDE** - Install [VS Code](https://code.visualstudio.com/) - -**Install Required Packages** - -* [Install dotnet](https://dotnet.microsoft.com/en-us/download/dotnet/6.0) -* Install aelf contract templates - -```bash -dotnet new --install AELF.ContractTemplates -``` - -AELF.ContractTemplates contains various predefined templates for the ease of developing smart contracts on the aelf blockchain. - -* Install aelf deploy tool - -```bash -dotnet tool install --global aelf.deploy -``` - -aelf.deploy is a utility tool for deploying smart contracts on the aelf blockchain. -Please remember to export PATH after installing aelf.deploy. - -**Install Node.js and Yarn** - -* [Install Node.js](https://nodejs.org/en) -* Install aelf-command - -```bash -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. -Provide required permissions while installing aelf-command globally. - - - - -1. Visit [aelf-devcontainer-template](https://github.com/AElfProject/aelf-devcontainer-template). -2. Click the `Use this template` button. Choose `Create a new repository`. -3. **Name Your Repository**: - Enter a suitable repository name. - Click **"Create repository"**. -4. **Access Codespaces**: - Within the GitHub interface of your new repository, click on **"Code"**. - Select **"Codespaces"**. -5. **Create a New Codespace**: - Click on the **"+"** sign to create a new Codespace. -6. **Wait for Your Workspace to Load**: - After some time, your workspace will load with the contents of the repository. - You can now continue your development using GitHub Codespaces. - - - - -## 2. Develop Smart Contract ### Start Your Smart Contract Project @@ -106,7 +40,7 @@ cd src The implementation of file `src/Protobuf/contract/lottery_game_contract.proto` is as follows: -```csharp +```csharp title= "src/Protobuf/contract/lottery_game_contract.proto" syntax = "proto3"; import "aelf/core.proto"; @@ -184,7 +118,7 @@ message PlayAmountLimitMessage { The implementation of file `src/LotteryGameState.cs` is as follows: -```csharp +```csharp title = "src/LotteryGameState.cs" using AElf.Sdk.CSharp.State; using AElf.Types; @@ -212,7 +146,7 @@ cd /src/Protobuf/reference Create a new file `token_contract.proto` under `src/Protobuf/reference/` The implementation of file `token_contract.proto` -```csharp +```csharp title = "token_contract.proto" /** * MultiToken contract. */ @@ -1111,10 +1045,10 @@ message SymbolAliasDeleted { #### Contract Reference State -Navigate to `src/` create a **new file** `ContractReferences.cs` +Navigate to `src` and create a **new file** `ContractReferences.cs` The implementation of file `src/ContractRefefrence.cs` is as follows: -```csharp +```csharp title ="src/ContractRefefrence.cs" using AElf.Contracts.MultiToken; namespace AElf.Contracts.LotteryGame @@ -1130,7 +1064,7 @@ namespace AElf.Contracts.LotteryGame Navigate to `src/LotteryGame.cs` -```csharp +```csharp title= "src/LotteryGame.cs" using AElf.Contracts.MultiToken; using AElf.Sdk.CSharp; using AElf.Types; @@ -1349,13 +1283,14 @@ namespace AElf.Contracts.LotteryGame #### Building Smart Contract -Build the new code with the following commands inside `src/` folder: +Build the new code with the following commands inside `src` folder: ```bash dotnet build ``` You should see **LotteryGame.dll.patched** in the directory `lottery_game/src/bin/Debug/net.6.0` +<<<<<<<< HEAD:docs/tutorials/dapp-development/lottery-game/index.md ## 3. Deploying Smart Contract @@ -1485,3 +1420,5 @@ You will be prompted for the following: Enter the required param : ELF Enter the required param : $WALLET_ADDRESS ``` +======== +>>>>>>>> 81b8bd1 (Changing folder for lotterybank):docs/tutorials/lottery-game/develop-smart-contract.md diff --git a/docs/tutorials/dapp-development/lottery-game/setup-enviornment.md b/docs/tutorials/dapp-development/lottery-game/setup-enviornment.md new file mode 100644 index 00000000..e88cf6d2 --- /dev/null +++ b/docs/tutorials/dapp-development/lottery-game/setup-enviornment.md @@ -0,0 +1,66 @@ +--- +sidebar_position: 1 +title: Setup Environment +description: Setup Environment for a vote smart contract +--- + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + + + + +- Basic knowledge of terminal commands +- **IDE** - Install [VS Code](https://code.visualstudio.com/) + +**Install Required Packages** + +- [Install dotnet](https://dotnet.microsoft.com/en-us/download/dotnet/6.0) +- Install aelf contract templates + +```bash +dotnet new --install AELF.ContractTemplates +``` + +AELF.ContractTemplates contains various predefined templates for the ease of developing smart contracts on the aelf blockchain. + +- Install aelf deploy tool + +```bash +dotnet tool install --global aelf.deploy +``` + +aelf.deploy is a utility tool for deploying smart contracts on the aelf blockchain. +Please remember to export PATH after installing aelf.deploy. + +**Install Node.js and Yarn** + +- [Install Node.js](https://nodejs.org/en) +- Install aelf-command + +```bash +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. +Provide required permissions while installing aelf-command globally. + + + + +1. Visit [aelf-devcontainer-template](https://github.com/AElfProject/aelf-devcontainer-template). + +2. Click the `Use this template` button. Choose `Create a new repository`. + +3. Enter a suitable repository name. Click `Create repository`. + +4. Within the GitHub interface of your new repository, click on `Code`. + Select `Codespaces`. + +5. Click on the `+` sign to create a new Codespace. + +6. After some time, your workspace will load with the contents of the repository. + You can now continue your development using GitHub Codespaces. + + + diff --git a/sidebars.ts b/sidebars.ts index 59589256..5437ddcd 100644 --- a/sidebars.ts +++ b/sidebars.ts @@ -23,6 +23,7 @@ const sidebars: SidebarsConfig = { }, items: [ { type: "doc", id: "quick-start/intro-to-aelf-development/index" }, + { type: "doc", id: "quick-start/hello-world/index" }, { type: "category", label: "Become a Node Operator", @@ -40,7 +41,10 @@ const sidebars: SidebarsConfig = { }, ], }, - { type: "doc", id: "quick-start/explore-running-aelf-side-chain/index" }, + { + type: "doc", + id: "quick-start/explore-running-aelf-side-chain/index", + }, ], }, ], @@ -189,6 +193,29 @@ const sidebars: SidebarsConfig = { }, ], }, + { + type: "category", + label: "Lottery Game Contract", + description: "Lottery Game Contract", + link: { + type: "generated-index", + slug: "/tutorials/lottery-game", + }, + items: [ + { + type: "doc", + id: "tutorials/lottery-game/setup-enviornment", + }, + { + type: "doc", + id: "tutorials/lottery-game/develop-smart-contract", + }, + { + type: "doc", + id: "tutorials/lottery-game/deploy-interact-smart-contract", + }, + ], + }, ], docs: [ {