Skip to content

Commit 4f572be

Browse files
Merge pull request #1170 from multiversx/dapp-tutorial
update dapp tutorial
2 parents 2e8c919 + 32c65a5 commit 4f572be

File tree

2 files changed

+32
-38
lines changed

2 files changed

+32
-38
lines changed

docs/developers/tutorials/your-first-dapp.md

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ title: Build a dApp in 15 minutes
55

66
[comment]: # (mx-abstract)
77

8-
Let's build your first decentralized application(dApp) on the MultiversX Blockchain!
8+
Let's build your first decentralized application (dApp) on the MultiversX Blockchain!
99

1010
## Prerequisites
1111

@@ -15,7 +15,7 @@ Before starting this tutorial, make sure you have the following:
1515
- `stable` Rust version `≥ 1.85.0` (install via [rustup](/docs/developers/toolchain-setup.md#installing-rust-and-sc-meta))
1616
- `multiversx-sc-meta` (cargo install [multiversx-sc-meta](/docs/developers/meta/sc-meta-cli.md))
1717
- `Node.js` with version `≥ 20`(guide [here](https://nodejs.org/en/download/package-manager))
18-
- `yarn` ([npm install --global yarn](https://classic.yarnpkg.com/lang/en/docs/install/#debian-stable) )
18+
- `pnpm` ([npm install --global pnpm](https://pnpm.io/installation) )
1919

2020
:::
2121

@@ -34,13 +34,13 @@ The **Ping-Pong app** is a very simple decentralized application that allows use
3434

3535
Endpoints available:
3636

37-
- `ping`: sending funds to the contract.
37+
- `ping`: sending funds to the contract;
3838
- `pong`: claiming the same amount back.
3939

4040
Rules:
4141

42-
- Each user can only `ping` once before they `pong`.
43-
- The `ping` amount must be exactly the specified valueno more, no less.
42+
- Each user can only `ping` once before they `pong`;
43+
- The `ping` amount must be exactly the specified value - no more, no less;
4444
- `pong` becomes available only after a set waiting period following a `ping`.
4545

4646
[comment]: # (mx-exclude-context)
@@ -55,7 +55,7 @@ Rules:
5555

5656
For the web application, we will have two pages:
5757

58-
- **Sign in** - The page where you can authenticate using the **xPortal app**, **Ledger**, **DeFi Wallet**, **xAlias**, **Web Wallet**, **Passkey Proxy** or with **Metamask proxy**;
58+
- **Sign in** - The page where you can authenticate using the **xPortal App**, **Ledger**, **DeFi Wallet**, **xAlias**, **Web Wallet**, **Passkey Proxy** or **Metamask Proxy**;
5959
- **Dashboard** - Here, you can either `ping` or `pong`. If you have already deposited, you will see a countdown timer until the time interval resets.
6060

6161
[comment]: # (mx-context-auto)
@@ -73,14 +73,14 @@ The contract also includes several views, storage mappers and one event:
7373
- `getPongEnableTimestamp`: **view** that provides the timestamp when `pong` will be available for a given address;
7474
- `getTimeToPong`: **view** that shows the remaining time until `pong` is enabled for a specific address;
7575
- `getAcceptedPaymentToken`: **storage mapper** that saves the token type allowed for deposits;
76-
- `getPingAmount`: **storage mapper** that records recording the total amount of tokens deposited;
77-
- `getDurationTimestamp`: **storage mapper** that saves the lock duration (in seconds) before `pong` can be called after a `ping`;
76+
- `getPingAmount`: **storage mapper** that records the total amount of tokens deposited;
77+
- `getDurationTimestamp`: **storage mapper** that saves the lock duration (in milliseconds) before `pong` can be called after a `ping`;
7878
- `getUserPingTimestamp`: **storage mapper** that saves the timestamp of the block where the user `ping`-ed;
7979
- `pongEvent`: **event** that signals a successful `pong` by the user with amount.
8080

8181
Think of this smart contract as the API for our dApp, handling all the core business logic.
8282

83-
To test it out, we will use [MultiversX Blockchain Devnet Explorer](https://devnet-explorer.multiversx.com/)a public test network maintained by our community.
83+
To test it out, we will use [MultiversX Blockchain Devnet Explorer](https://devnet-explorer.multiversx.com/) - a public test network maintained by our community.
8484

8585
[comment]: # (mx-context-auto)
8686

@@ -107,7 +107,7 @@ By the time we are done, our project will have three subfolders: wallet, contrac
107107

108108
### Create wallet
109109

110-
To deploy a smart contract to the blockchain, you will need a wallet-a PEM file is recommended for simplicity and ease of testing.
110+
To deploy a smart contract to the blockchain, you will need a wallet: a **PEM file** is recommended for simplicity and ease of testing.
111111

112112
:::important
113113
Make sure you are in the `ping-pong/` folder before continuing.
@@ -124,7 +124,7 @@ PEM wallets are recommended only for testing and experimenting with non-producti
124124

125125
To initiate transactions on the blockchain, your wallet needs funds to cover transaction fees, commonly referred to as **gas**.
126126

127-
The [MultiversX Devnet](https://devnet-wallet.multiversx.com/dashboard) offers a **faucet** where you can claim **5 EGLD every 24 hours**. Here’s how to fund your wallet:
127+
The [MultiversX Devnet](https://devnet-wallet.multiversx.com/dashboard) offers a **faucet** where you can claim **5 EGLD**. You can recall the faucet every **24 hours** if your balance is **lower than 1 EGLD**. Here’s how to fund your wallet:
128128

129129
1. Go to [Devnet Wallet MultiversX](https://devnet-wallet.multiversx.com/unlock/pem) and log in using your newly generated **PEM** file;
130130
2. Once logged in, open the **Faucet** from the **Tools**;
@@ -136,9 +136,9 @@ The [MultiversX Devnet](https://devnet-wallet.multiversx.com/dashboard) offers a
136136

137137
## The Blockchain Layer
138138

139-
With the wallet setup complete, let's move on to the backendthe blockchain layer.
139+
With the wallet setup complete, let's move on to the backend - the blockchain layer.
140140

141-
Let's start with the smart contract. You will first clone the Ping-Pong sample contract repository from [here](https://github.com/multiversx/mx-ping-pong-sc).
141+
Let's start with the smart contract. You will first clone the Ping-Pong sample contract [repository](https://github.com/multiversx/mx-ping-pong-sc).
142142

143143
:::important
144144
Make sure you are still in the `ping-pong/` folder.
@@ -154,7 +154,7 @@ This will create a **contract** folder within ping-pong, containing all the nece
154154

155155
### Build the Smart Contract
156156

157-
Now that you have the source code for the smart contract, you need to compile it into a **binary** that the **MultiversX Virtual Machine** can execute. Since the VM runs Web Assembly (WASM) code, you need to compile our Rust source code into a WASM file.
157+
Now that you have the source code for the smart contract, you need to compile it into a **binary** that the **MultiversX Virtual Machine** (VM) can execute. Since the VM runs Web Assembly (WASM) code, you need to compile our Rust source code into a WASM file.
158158

159159
At path `ping-pong/`, run the following command to build the smart contract into a WASM file.
160160

@@ -179,32 +179,30 @@ Ensure that `wallet_owner.pem` is in the `wallet/` folder and that the smart con
179179

180180
Before deploying, you will need to modify the wallet from which transactions are made. Currently, they are made from a test wallet. To use the wallet you created [earlier](./your-first-dapp.md#create-wallet), you will need to make the following changes:
181181

182-
In the file `interact.rs` located at the path `ping-pong/contract/ping-pong/interactor/src`, the variable `alice_wallet_address` from `new` function will be modified.
182+
In the file [`interact.rs`](https://github.com/multiversx/mx-ping-pong-sc/blob/e1b3e0e9657e83ad11cc0069c0fc7183f91a2fe1/ping-pong/interactor/src/interact.rs#L84) located at the path `ping-pong/contract/ping-pong/interactor/src`, the variable `wallet_address_1` from `new` function will be modified.
183183

184184
```rust title="Before"
185-
let alice_wallet_address = interactor.register_wallet(test_wallets::alice()).await;
185+
let wallet_address_1 = interactor.register_wallet(test_wallets::alice()).await;
186186
```
187187

188188
```rust title="After"
189-
let alice_wallet_address = interactor
189+
let wallet_address_1 = interactor
190190
.register_wallet(Wallet::from_pem_file("../../../wallet/wallet-owner.pem").unwrap())
191191
.await;
192192
```
193193

194194
:::note
195195
You need to replace with the relative path from the **interactor crate** to the **created wallet**.
196196

197-
The interactor crate is located at `ping-pong/contract/ping-pong/interactor` and the wallet is in a higher-level directory: `ping-pong/wallet`.
197+
The interactor crate is located at `ping-pong/contract/ping-pong/interactor`, and the wallet is in a higher-level directory: `ping-pong/wallet`.
198198

199-
To access `wallet-owner.pem` you must navigate up three folders: `../../../`, then into the **wallet** directory.
199+
Alternatively, you can add the absolute path of `wallet-owner.pem`.
200200
:::
201201

202-
Make sure to add the absolute path at `Wallet::from_pem_file("/ping-pong/wallet/wallet-owner.pem")`, completing the missing directories above "ping-pong".
203-
204202
This next command deploys the Ping-Pong contract with the following settings:
205203

206204
- Ping Amount: **1 EGLD**.
207-
- Lock Duration: **180 seconds** (3 minutes).
205+
- Lock Duration: **180000 milliseconds** (3 minutes).
208206

209207
:::important
210208
Ensure that you run the next command inside the **interactor** crate, located at:
@@ -213,23 +211,23 @@ Ensure that you run the next command inside the **interactor** crate, located at
213211
:::
214212

215213
```bash
216-
cargo run deploy --ping-amount 1000000000000000000 --duration-in-seconds 180
214+
cargo run deploy --amount 1000000000000000000 --duration 180000
217215
```
218216

219217
```sh title=output
220218
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.48s
221-
Running `/ping-pong/contract/target/debug/ping-pong-interact deploy --ping-amount 1000000000000000000 --duration-in-seconds 180`
222-
sender's recalled nonce: 12422
223-
-- tx nonce: 12422
224-
sc deploy tx hash: b6ca6c8e6ac54ed168bcd6929e762610e2360674f562115107cf3702b8a22467
225-
deploy address: erd1qqqqqqqqqqqqqpgqymj43x6anzr38jfz7kw3td2ew33v9jtrd8sse5zzk6
226-
new address: erd1qqqqqqqqqqqqqpgqymj43x6anzr38jfz7kw3td2ew33v9jtrd8sse5zzk6
219+
Running `/ping-pong/contract/target/debug/ping-pong-interact deploy --amount 1000000000000000000 --duration 180000`
220+
sender's recalled nonce: 0
221+
-- tx nonce: 0
222+
sc deploy tx hash: 93ff495b02eb84f0f427f4f02e2c0ce10e667a3511807db8781e1eaed47f9d16
223+
deploy address: erd1qqqqqqqqqqqqqpgq0dw0cfqeknm43sxzzeg5h5j3ewwu8gyd0vdqq4jutd
224+
new address: erd1qqqqqqqqqqqqqpgq0dw0cfqeknm43sxzzeg5h5j3ewwu8gyd0vdqq4jutd
227225
```
228226
229227
Once the command runs, review the log output carefully. Two key details to note:
230228
231-
- Contract Address: in the example presented below is erd1qqqqqqqqqqqqqpgqymj43x6anzr38jfz7kw3td2ew33v9jtrd8sse5zzk6
232-
- Transaction Hash: in the example presented below is b6ca6c8e6ac54ed168bcd6929e762610e2360674f562115107cf3702b8a22467
229+
- **Contract Address**: in the example presented below, it is erd1qqqqqqqqqqqqqpgq0dw0cfqeknm43sxzzeg5h5j3ewwu8gyd0vdqq4jutd
230+
- **Transaction Hash**: in the example presented below, it is 93ff495b02eb84f0f427f4f02e2c0ce10e667a3511807db8781e1eaed47f9d16
233231
234232
We will take a look at the transaction details. Let's check them in the [Devnet Explorer](https://devnet-explorer.multiversx.com).
235233

@@ -276,23 +274,19 @@ Then edit this instruction and change it to the contract address that you create
276274

277275
![img](/developers/tutorial/config-screenshot.png)
278276

279-
:::important
280-
Make sure you have [**yarn installed**](https://classic.yarnpkg.com/lang/en/docs/install) on your machine.
281-
:::
282-
283277
Navigate to the `ping-pong/dapp` folder and install the required dependencies:
284278

285279
```sh
286-
npm install --global yarn
287-
yarn add vite --dev
280+
npm install --global pnpm
281+
pnpm install
288282
```
289283

290284
### Start the Development Server
291285

292286
To test your dApp locally, start a development server with the following command:
293287

294288
```sh
295-
yarn start:devnet
289+
pnpm start-devnet
296290
```
297291

298292
### Running and Accessing the dApp
-177 KB
Loading

0 commit comments

Comments
 (0)