Skip to content

Commit 7c5301a

Browse files
tutorial polish
1 parent 7fbd6e5 commit 7c5301a

File tree

2 files changed

+29
-52
lines changed

2 files changed

+29
-52
lines changed

tutorials/dapps/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
title: Decentralized Application Tutorials
3-
description: Explore step-by-step tutorials for building applications using the toolkits that Polkadot provides.
3+
description: Explore step-by-step tutorials for exploring the world of building decentralized applications using the toolkits that Polkadot provides.
44
template: index-page.html
55
---

tutorials/dapps/papi/remark-tutorial.md

Lines changed: 28 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
11
---
22
title: Polkadot API Account Watcher Tutorial
3-
description: This tutorial will focus on learning how to build a decentralized command line application using the Polkadot API.
3+
description: Learn how to build a decentralized command-line application using the Polkadot API.
44
---
55

6-
### Project Introduction
6+
!!!info "This tutorial uses the Westend Test Network"
7+
Ensure you have an account with WND tokens before proceeding with this tutorial.
78

8-
Our project will be quite simple - it will be a CLI application that runs in the terminal, which watches the relay chain for a certain `extrinsic` (a transaction). This extrinsic will be the `system.remarkWithEvent` extrinsic, meaning it is coming from the `system` pallet (module) on the Westend test network.
9+
### Introduction
910

10-
The `system.remarkWithEvent` extrinsic allows us to send any arbitrary data on-chain, with the end result being a hash that is the address and the word "email" combined (`address+email`). We'll hash this combination and watch for remarks on a chain that are addressed to us. The `system.remarkWithEvent` extrinsic emits an event that we can use PAPI to watch the chain for.
11+
This tutorial demonstrates how to build a simple command-line interface (CLI) application that monitors a user's account on the relay chain for the `system.remarkWithEvent` extrinsic.
1112

12-
Once we receive a remark addressed to us, we will play the infamous "You've Got Mail!" sound byte.
13+
The `system.remarkWithEvent` extrinsic enables the submission of arbitrary data on-chain. In this tutorial, the data consists of a hash derived from the combination of an account address and the word "email" (`address+email`). This hash is monitored on-chain, and the application listens for remarks addressed to the specified account. The `system.remarkWithEvent` extrinsic emits an event that can be observed using the Polkadot API (PAPI).
14+
15+
Upon detecting a remark addressed to the specified account, the application plays the iconic "You've Got Mail!" sound byte.
1316

1417
### Prerequisites
1518

16-
You should have the following installed as a prerequisite:
19+
Before starting, ensure the following tools and dependencies are installed:
1720

18-
- `npm` (or other package manager)
21+
- `npm` (or an alternative package manager)
1922
- `node`
2023
- `git`
2124
- [Polkadot.js Browser Extension (wallet)](https://polkadot.js.org/extension/)
2225

23-
You will also need an account with Westend tokens. Below you can find guides for both Polkadot.js and the faucet:
26+
Additionally, you will need an account with Westend tokens. Refer to the following resources for assistance:
2427

25-
- [Creating Accounts on Polkadot.js](https://www.youtube.com/watch?v=DNU0p5G0Gqc)
2628
- [Westend Faucet](https://faucet.polkadot.io/westend)
2729

28-
### Cloning the repository
29-
30-
For this tutorial, you can choose to run the example directly by cloning the [main branch of the repository](https://github.com/CrackTheCode016/polkadot-api-example-cli/tree/main), or to use a boilerplate/template and follow the tutorial.
30+
### Cloning the Repository
3131

32-
We need to clone the template, which has everything we need to get started with the Polkadot API and Typescript. Be sure you clone the correct branch (`empty-cli`) which already provides all dependencies:
32+
To follow this tutorial, you can either run the example directly or use a boilerplate/template. This tutorial uses a template that includes all necessary dependencies for working with the Polkadot API and TypeScript. Clone the appropriate branch (`empty-cli`) of the repository as follows:
3333

3434
```shell
3535
git clone https://github.com/CrackTheCode016/polkadot-api-example-cli --branch empty-cli
3636
```
3737

38-
Once cloned, run the following to ensure `npm` dependencies are installed:
38+
After cloning, install the required dependencies by running:
3939

4040
```shell
4141
cd polkadot-api-example-cli
4242
npm install
4343
```
4444

45-
### Exploring the Template (Light Clients!)
45+
### Exploring the Template (Light Clients)
4646

47-
When we open the repository, we should see the following code (excluding imports):
47+
Upon opening the repository, you will find the following code (excluding imports):
4848

4949
```typescript
5050
async function withLightClient(): Promise<PolkadotClient> {
@@ -64,11 +64,11 @@ async function main() {
6464
main()
6565
```
6666

67-
The notable function to pay attention to is the `withLightClient` function. This function uses the built in light client functionality (powered by [`smoldot`](https://github.com/smol-dot/smoldot)) to actually create a light client that syncs and interacts with Polkadot right there in our application.
67+
The `withLightClient` function is of particular importance. It leverages the built-in light client functionality, powered by [`smoldot`](https://github.com/smol-dot/smoldot), to create a light client that synchronizes and interacts with Polkadot directly within the application.
6868

6969
### Creating the CLI
7070

71-
Next, let's create our CLI, which is to be done within the confines of the `main` function. We will include an option (`-a` / `--account`), which will be the account we will watch for our "mail":
71+
The CLI functionality is implemented within the `main` function. The CLI includes an option (`-a` / `--account`) to specify the account to monitor for remarks:
7272

7373
```ts
7474
const program = new Command();
@@ -83,7 +83,7 @@ const options = program.opts();
8383

8484
### Watching for Remarks
8585

86-
Next, we need to start watching the Westend network for remarks sent to our account. As was done before, all code should be within the `main` function:
86+
The application monitors the Westend network for remarks sent to the specified account. The following code, placed within the `main` function, implements this functionality:
8787

8888
```typescript
8989
// We check for the --account flag, if its not provided we exit
@@ -114,24 +114,15 @@ Next, we need to start watching the Westend network for remarks sent to our acco
114114
}
115115
```
116116

117-
This code is doing quite a bit, so let's break it down:
118-
119-
- First, we check for the existance of the `--account` argument, and log that we are watching that account, else we exit. We are using the `chalk` package to add color to our `console.log` statements.
120-
- Next, we create our light client.
121-
- We use a light client and the Westend chain specification (`wnd`) to access a typed API.
122-
- Once we have our API, we then begin to reactively watch the account for the event that corresponds to the remark. We analyze the payload, looking for a hash which is calculated as follows:
123-
- hash of: `account_address+email`
124-
- When an event containing this hash is identified, it then plays the "You've Got Mail!" soundbite.
117+
### Compiling and Running
125118

126-
### Compiling and running
127-
128-
Once we have all of our code in place, we should compile and run the repository:
119+
Compile and execute the application using the following command:
129120

130121
```shell
131122
npm start -- --account <account-address>
132123
```
133124

134-
Upon running, we should have the following output:
125+
For example:
135126

136127
```shell
137128
❯ npm start -- --account 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
@@ -150,29 +141,15 @@ Watching account: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
150141
[smoldot] Chain initialization complete for westend2. Name: "Westend". Genesis hash: 0xe143…423e. Chain specification starting at: 0x10cf…b908 (#23920337)
151142
```
152143
153-
## Testing the CLI
154-
155-
Now that our application is actively watching for remark events on-chain, we can move to testing to see if it works!
156-
157-
> As mentioned previously, you will need a Westend account with some tokens to pay for fees.
144+
### Testing the CLI
158145
159-
Navigate to the [PAPI Dev Console > Extrinsics](https://dev.papi.how/extrinsics#networkId=westend&endpoint=light-client). You then want to select the `System` pallet, and the `remark_with_event` call:
146+
To test the application, navigate to the [PAPI Dev Console > Extrinsics](https://dev.papi.how/extrinsics#networkId=westend&endpoint=light-client). Select the `System` pallet and the `remark_with_event` call.
160147
161-
![Screenshot 2025-03-03 at 4.54.29 PM](https://hackmd.io/_uploads/S1sESjXjyl.png)
162-
163-
Next, we want to be sure we get the correct input for the text field. We want to be sure we are following the convention we set forth in our application:
164-
165-
- `address+email`
166-
167-
If for example, we are watching `5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY`, then the field should look like the following:
148+
Ensure the input field follows the convention `address+email`. For example, if monitoring `5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY`, the input should be:
168149
169150
![Screenshot 2025-03-03 at 4.58.04 PM](https://hackmd.io/_uploads/S1nx8omo1x.png)
170151
171-
Once this input is in place, you may click the `Submit extrinsic` button, where you can sign using the Polkadot.js browser wallet:
172-
173-
![Screenshot 2025-03-03 at 5.00.20 PM](https://hackmd.io/_uploads/BkktUjQi1l.png)
174-
175-
Heading back to our CLI, we should soon see the following, along with the fact that "YOU'VE GOT MAIL!" (as in the sound should play):
152+
Submit the extrinsic and sign it using the Polkadot.js browser wallet. The CLI will display the following output and play the "You've Got Mail!" sound:
176153
177154
```
178155
__ __ _ _____ __ __ _ _ __ __ _ _
@@ -187,6 +164,6 @@ From: 5Cm8yiG45rqrpyV2zPLrbtr8efksrRuCXcqcB4xj8AejfcTB
187164
Hash: 0xb6999c9082f5b1dede08b387404c9eb4eb2deee4781415dfa7edf08b87472050
188165
```
189166
190-
## Conclusion
167+
### Conclusion
191168
192-
This application can be expanded in a number of ways, whether that is by adding a chatroom through remarks, or by using some of the rollups on Polkadot to expand the functionality.
169+
This application can be extended in various ways, such as implementing a chatroom using remarks or leveraging rollups on Polkadot to enhance functionality.

0 commit comments

Comments
 (0)