You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: Learn how to build a decentralized command-line application using the Polkadot API.
19673
+
---
19674
+
19675
+
## Introduction
19676
+
19677
+
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`](https://paritytech.github.io/polkadot-sdk/master/frame_system/pallet/struct.Pallet.html#method.remark_with_event){target=\_blank} extrinsic.
19678
+
19679
+
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).
19680
+
19681
+
When the application detects a remark addressed to the specified account, it plays the "You've Got Mail!" sound byte.
19682
+
19683
+
## Prerequisites
19684
+
19685
+
Before starting, ensure the following tools and dependencies are installed:
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:
After cloning, install the required dependencies by running:
19704
+
19705
+
```bash
19706
+
cd polkadot-api-example-cli
19707
+
npm install
19708
+
```
19709
+
19710
+
## Explore the Template (Light Clients)
19711
+
19712
+
After opening the repository, you will find the following code (excluding imports):
19713
+
19714
+
```typescript title="index.ts"
19715
+
code/develop/dapps/papi/remark-tutorial/index.ts
19716
+
```
19717
+
19718
+
The `withLightClient` function is particularly important. It uses the built-in light client functionality, powered by [`smoldot`](https://github.com/smol-dot/smoldot){target=\_blank}, to create a light client that synchronizes and interacts with Polkadot directly within the application.
19719
+
19720
+
## Create the CLI
19721
+
19722
+
The CLI functionality is implemented within the `main` function. The CLI includes an option (`-a` / `--account`) to specify the account to monitor for remarks:
19723
+
19724
+
```typescript title="index.ts"
19725
+
code/develop/dapps/papi/remark-tutorial/cli.ts
19726
+
```
19727
+
19728
+
## Watch for Remarks
19729
+
19730
+
The application monitors the Westend network for remarks sent to the specified account. The following code, placed within the `main` function, implements this functionality:
To test the application, navigate to the [PAPI Dev Console > Extrinsics](https://dev.papi.how/extrinsics#networkId=westend&endpoint=light-client){target=\_blank}. Select the `System` pallet and the `remark_with_event` call.
19787
+
19788
+
Ensure the input field follows the convention `address+email`. For example, if monitoring `5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY`, the input should be:
19789
+
19790
+

19791
+
19792
+
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:
This application demonstrates how the Polkadot API can be used to build decentralized applications. While this is not a production-grade application, it introduces several key features for developing with the Polkadot API.
19810
+
19811
+
To explore more, refer to the [official PAPI documentation](https://papi.how){target=\_blank}.
Copy file name to clipboardExpand all lines: tutorials/dapps/papi/remark-tutorial.md
+13-63Lines changed: 13 additions & 63 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,12 +3,9 @@ title: Polkadot API Account Watcher Tutorial
3
3
description: Learn how to build a decentralized command-line application using the Polkadot API.
4
4
---
5
5
6
-
!!!info "This tutorial uses the Westend Test Network"
7
-
Ensure you have an account with WND tokens before proceeding with this tutorial.
8
-
9
6
## Introduction
10
7
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.
8
+
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`](https://paritytech.github.io/polkadot-sdk/master/frame_system/pallet/struct.Pallet.html#method.remark_with_event){target=\_blank} extrinsic.
12
9
13
10
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
11
@@ -18,9 +15,8 @@ When the application detects a remark addressed to the specified account, it pla
18
15
19
16
Before starting, ensure the following tools and dependencies are installed:
Additionally, you need an account with Westend tokens. Refer to the following resources for assistance:
@@ -31,13 +27,13 @@ Additionally, you need an account with Westend tokens. Refer to the following re
31
27
32
28
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:
The `withLightClient` function is particularly important. It uses the built-in light client functionality, powered by [`smoldot`](https://github.com/smol-dot/smoldot){target=\_blank}, to create a light client that synchronizes and interacts with Polkadot directly within the application.
@@ -71,60 +52,29 @@ The `withLightClient` function is particularly important. It uses the built-in l
71
52
72
53
The CLI functionality is implemented within the `main` function. The CLI includes an option (`-a` / `--account`) to specify the account to monitor for remarks:
73
54
74
-
```typescript
75
-
// filepath: /path/to/repository/src/index.ts
76
-
const program =newCommand();
77
-
console.log(chalk.white.dim(figlet.textSync("Web3 Mail Watcher")));
78
-
program
79
-
.version('0.0.1')
80
-
.description('Web3 Mail Watcher - A simple CLI tool to watch for remarks on the Polkadot network')
81
-
.option('-a, --account <account>', 'Account to watch')
The application monitors the Westend network for remarks sent to the specified account. The following code, placed within the `main` function, implements this functionality:
0 commit comments