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
Copy file name to clipboardExpand all lines: .chain-interactions/accounts/query-accounts.md
+62-47Lines changed: 62 additions & 47 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
title: Query Account Information with SDKs
3
-
description: Learn how to query account information using five popular SDKs: Polkadot API (PAPI), Polkadot.js API, Dedot, Python Substrate Interface, and Subxt.
3
+
description: Learn how to query account information using five popular SDKs—Polkadot API (PAPI), Polkadot.js API, Dedot, Python Substrate Interface, and Subxt.
4
4
categories: Basics, Polkadot Protocol
5
5
---
6
6
@@ -12,17 +12,14 @@ Querying account information is a fundamental operation when interacting with Po
12
12
13
13
This guide demonstrates how to query account information using five popular SDKs:
14
14
15
-
-**[Polkadot API (PAPI)](/reference/tools/papi/){target=\_blank}** - Modern TypeScript library with type-safe APIs
-**[Dedot](/reference/tools/dedot/){target=\_blank}**: Lightweight TypeScript library optimized for performance
18
+
-**[Python Substrate Interface](/reference/tools/py-substrate-interface/){target=\_blank}**: Python library for Substrate chains
19
+
-**[Subxt](/reference/tools/subxt/){target=\_blank}**: Rust library with compile-time type safety
20
20
21
21
Select your preferred SDK below to see complete, runnable examples that query account information on Polkadot Hub.
22
22
23
-
!!! note
24
-
Ensure to replace `INSERT_WS_ENDPOINT` with the proper WebSocket endpoint and `INSERT_ACCOUNT_ADDRESS` with the account address you want to query. For this example, you can use Polkadot Hub (`wss://asset-hub-paseo.dotters.network`).
25
-
26
23
## Prerequisites
27
24
28
25
- Access to a Polkadot SDK-compatible blockchain endpoint (WebSocket URL)
@@ -32,8 +29,6 @@ Select your preferred SDK below to see complete, runnable examples that query ac
32
29
33
30
=== "PAPI"
34
31
35
-
[Polkadot API (PAPI)](/reference/tools/papi/){target=\_blank} is a modern, type-safe TypeScript library optimized for light-client functionality.
36
-
37
32
**Prerequisites**
38
33
39
34
- [Node.js](https://nodejs.org/){target=\_blank} v18 or higher
@@ -65,12 +60,15 @@ Select your preferred SDK below to see complete, runnable examples that query ac
65
60
66
61
The following example queries account information including balance, nonce, and other account data.
67
62
68
-
Create a file named `query-account.ts`:
63
+
Create a file named `query-account.ts` and add the following code to it:
Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://asset-hub-paseo.dotters.network`) and `INSERT_ADDRESS` with the account address you want to query.
71
+
74
72
Run the script:
75
73
76
74
```bash
@@ -79,16 +77,14 @@ Select your preferred SDK below to see complete, runnable examples that query ac
The Polkadot.js API is no longer actively developed. New projects should use [PAPI](/reference/tools/papi/){target=\_blank} or [Dedot](/reference/tools/dedot/){target=\_blank} as actively maintained alternatives.
89
87
90
-
[Polkadot.js API](/reference/tools/polkadot-js-api/){target=\_blank} is a comprehensive JavaScript library with extensive ecosystem support.
91
-
92
88
**Prerequisites**
93
89
94
90
- [Node.js](https://nodejs.org/){target=\_blank} v18 or higher
@@ -113,12 +109,15 @@ Select your preferred SDK below to see complete, runnable examples that query ac
113
109
114
110
The following example queries account information including balance, nonce, and other account data.
115
111
116
-
Create a file named `query-account.js`:
112
+
Create a file named `query-account.js` and add the following code to it:
Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://asset-hub-paseo.dotters.network`) and `INSERT_ADDRESS` with the account address you want to query.
120
+
122
121
Run the script:
123
122
124
123
```bash
@@ -127,12 +126,10 @@ Select your preferred SDK below to see complete, runnable examples that query ac
[Dedot](/reference/tools/dedot/){target=\_blank} is a next-generation TypeScript client that's lightweight, tree-shakable, and maintains API compatibility with Polkadot.js.
135
-
136
133
**Prerequisites**
137
134
138
135
- [Node.js](https://nodejs.org/){target=\_blank} v18 or higher
@@ -158,12 +155,15 @@ Select your preferred SDK below to see complete, runnable examples that query ac
158
155
159
156
The following example queries account information including balance, nonce, and other account data.
160
157
161
-
Create a file named `query-account.ts`:
158
+
Create a file named `query-account.ts` and add the following code to it:
Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://asset-hub-paseo.dotters.network`) and `INSERT_ADDRESS` with the account address you want to query.
166
+
167
167
Run the script:
168
168
169
169
```bash
@@ -172,11 +172,9 @@ Select your preferred SDK below to see complete, runnable examples that query ac
[Python Substrate Interface](/reference/tools/py-substrate-interface/){target=\_blank} provides a Python library for interacting with Substrate-based chains.
177
+
=== "Python Substrate Interface"
180
178
181
179
**Prerequisites**
182
180
@@ -202,12 +200,15 @@ Select your preferred SDK below to see complete, runnable examples that query ac
202
200
203
201
The following example queries account information including balance, nonce, and other account data.
204
202
205
-
Create a file named `query_account.py`:
203
+
Create a file named `query_account.py` and add the following code to it:
Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://asset-hub-paseo.dotters.network`) and `INSERT_ADDRESS` with the account address you want to query.
211
+
211
212
Run the script:
212
213
213
214
```bash
@@ -216,12 +217,10 @@ Select your preferred SDK below to see complete, runnable examples that query ac
Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://asset-hub-paseo.dotters.network`) and `INSERT_ADDRESS` with the account address you want to query.
278
+
277
279
Run the script:
278
280
279
281
```bash
@@ -282,27 +284,40 @@ Select your preferred SDK below to see complete, runnable examples that query ac
Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query.
64
+
!!! note
65
+
Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query.
65
66
66
67
Run the script:
67
68
@@ -83,7 +84,8 @@ Select your preferred SDK below to see complete, runnable examples that query Po
Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query.
87
+
!!! note
88
+
Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query.
87
89
88
90
Run the script:
89
91
@@ -130,7 +132,8 @@ Select your preferred SDK below to see complete, runnable examples that query Po
Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query.
135
+
!!! note
136
+
Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query.
134
137
135
138
Run the script:
136
139
@@ -152,8 +155,9 @@ Select your preferred SDK below to see complete, runnable examples that query Po
Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query.
156
-
158
+
!!! note
159
+
Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query.
160
+
157
161
Run the script:
158
162
159
163
```bash
@@ -197,7 +201,8 @@ Select your preferred SDK below to see complete, runnable examples that query Po
Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query.
204
+
!!! note
205
+
Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query.
201
206
202
207
Run the script:
203
208
@@ -219,7 +224,8 @@ Select your preferred SDK below to see complete, runnable examples that query Po
Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query.
227
+
!!! note
228
+
Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query.
223
229
224
230
Run the script:
225
231
@@ -263,7 +269,8 @@ Select your preferred SDK below to see complete, runnable examples that query Po
Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query.
272
+
!!! note
273
+
Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query.
267
274
268
275
Run the script:
269
276
@@ -285,7 +292,8 @@ Select your preferred SDK below to see complete, runnable examples that query Po
Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query.
295
+
!!! note
296
+
Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query.
289
297
290
298
Run the script:
291
299
@@ -326,7 +334,8 @@ Select your preferred SDK below to see complete, runnable examples that query Po
Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query.
356
+
!!! note
357
+
Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query.
348
358
349
359
Run the script:
350
360
@@ -369,7 +379,8 @@ Select your preferred SDK below to see complete, runnable examples that query Po
Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query.
382
+
!!! note
383
+
Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query.
0 commit comments