Skip to content

Commit 9e22b01

Browse files
committed
update account query page and similar pages for consistency
1 parent 04a6bc9 commit 9e22b01

File tree

19 files changed

+266
-200
lines changed

19 files changed

+266
-200
lines changed

.chain-interactions/accounts/query-accounts.md

Lines changed: 62 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
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 SDKsPolkadot API (PAPI), Polkadot.js API, Dedot, Python Substrate Interface, and Subxt.
44
categories: Basics, Polkadot Protocol
55
---
66

@@ -12,17 +12,14 @@ Querying account information is a fundamental operation when interacting with Po
1212

1313
This guide demonstrates how to query account information using five popular SDKs:
1414

15-
- **[Polkadot API (PAPI)](/reference/tools/papi/){target=\_blank}** - Modern TypeScript library with type-safe APIs
16-
- **[Polkadot.js API](/reference/tools/polkadot-js-api/){target=\_blank}** - Comprehensive JavaScript library (maintenance mode)
17-
- **[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
15+
- **[Polkadot API (PAPI)](/reference/tools/papi/){target=\_blank}**: Modern TypeScript library with type-safe APIs
16+
- **[Polkadot.js API](/reference/tools/polkadot-js-api/){target=\_blank}**: Comprehensive JavaScript library (maintenance mode)
17+
- **[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
2020

2121
Select your preferred SDK below to see complete, runnable examples that query account information on Polkadot Hub.
2222

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-
2623
## Prerequisites
2724

2825
- 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
3229

3330
=== "PAPI"
3431

35-
[Polkadot API (PAPI)](/reference/tools/papi/){target=\_blank} is a modern, type-safe TypeScript library optimized for light-client functionality.
36-
3732
**Prerequisites**
3833

3934
- [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
6560

6661
The following example queries account information including balance, nonce, and other account data.
6762

68-
Create a file named `query-account.ts`:
63+
Create a file named `query-account.ts` and add the following code to it:
6964

7065
```typescript title="query-account.ts"
71-
--8<-- "code/chain-interactions/accounts/query-account/papi-query-account.ts"
66+
--8<-- "code/chain-interactions/accounts/query-account/papi/query-account.ts"
7267
```
7368

69+
!!! note
70+
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+
7472
Run the script:
7573

7674
```bash
@@ -79,16 +77,14 @@ Select your preferred SDK below to see complete, runnable examples that query ac
7977

8078
You should see output similar to:
8179

82-
--8<-- "code/chain-interactions/accounts/query-account/papi-query-account-output.html"
80+
--8<-- "code/chain-interactions/accounts/query-account/papi/query-account-output.html"
8381

8482

8583
=== "Polkadot.js"
8684

8785
!!! warning "Maintenance Mode Only"
8886
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.
8987

90-
[Polkadot.js API](/reference/tools/polkadot-js-api/){target=\_blank} is a comprehensive JavaScript library with extensive ecosystem support.
91-
9288
**Prerequisites**
9389

9490
- [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
113109

114110
The following example queries account information including balance, nonce, and other account data.
115111

116-
Create a file named `query-account.js`:
112+
Create a file named `query-account.js` and add the following code to it:
117113

118114
```javascript title="query-account.js"
119-
--8<-- "code/chain-interactions/accounts/query-account/polkadot-js-query-account.js"
115+
--8<-- "code/chain-interactions/accounts/query-account/pjs/query-account.js"
120116
```
121117

118+
!!! note
119+
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+
122121
Run the script:
123122

124123
```bash
@@ -127,12 +126,10 @@ Select your preferred SDK below to see complete, runnable examples that query ac
127126

128127
You should see output similar to:
129128

130-
--8<-- "code/chain-interactions/accounts/query-account/polkadot-js-query-account-output.html"
129+
--8<-- "code/chain-interactions/accounts/query-account/pjs/query-account-output.html"
131130

132131
=== "Dedot"
133132

134-
[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-
136133
**Prerequisites**
137134

138135
- [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
158155

159156
The following example queries account information including balance, nonce, and other account data.
160157

161-
Create a file named `query-account.ts`:
158+
Create a file named `query-account.ts` and add the following code to it:
162159

163160
```typescript title="query-account.ts"
164-
--8<-- "code/chain-interactions/accounts/query-account/dedot-query-account.ts"
161+
--8<-- "code/chain-interactions/accounts/query-account/dedot/query-account.ts"
165162
```
166163

164+
!!! note
165+
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+
167167
Run the script:
168168

169169
```bash
@@ -172,11 +172,9 @@ Select your preferred SDK below to see complete, runnable examples that query ac
172172

173173
You should see output similar to:
174174

175-
--8<-- "code/chain-interactions/accounts/query-account/dedot-query-account-output.html"
176-
177-
=== "Python"
175+
--8<-- "code/chain-interactions/accounts/query-account/dedot/query-account-output.html"
178176

179-
[Python Substrate Interface](/reference/tools/py-substrate-interface/){target=\_blank} provides a Python library for interacting with Substrate-based chains.
177+
=== "Python Substrate Interface"
180178

181179
**Prerequisites**
182180

@@ -202,12 +200,15 @@ Select your preferred SDK below to see complete, runnable examples that query ac
202200

203201
The following example queries account information including balance, nonce, and other account data.
204202

205-
Create a file named `query_account.py`:
203+
Create a file named `query_account.py` and add the following code to it:
206204

207205
```python title="query_account.py"
208-
--8<-- "code/chain-interactions/accounts/query-account/psi_query_account.py"
206+
--8<-- "code/chain-interactions/accounts/query-account/psi/query_account.py"
209207
```
210208

209+
!!! note
210+
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+
211212
Run the script:
212213

213214
```bash
@@ -216,12 +217,10 @@ Select your preferred SDK below to see complete, runnable examples that query ac
216217

217218
You should see output similar to:
218219

219-
--8<-- "code/chain-interactions/accounts/query-account/psi-query-account-output.html"
220+
--8<-- "code/chain-interactions/accounts/query-account/psi/query-account-output.html"
220221

221222
=== "Subxt"
222223

223-
[Subxt](/reference/tools/subxt/){target=\_blank} is a Rust library that provides compile-time type safety through code generation from chain metadata.
224-
225224
**Prerequisites**
226225

227226
- [Rust](https://rustup.rs/){target=\_blank} toolchain (latest stable)
@@ -268,12 +267,15 @@ Select your preferred SDK below to see complete, runnable examples that query ac
268267

269268
The following example queries account information including balance, nonce, and other account data.
270269

271-
Create a file at `src/bin/query_account.rs`:
270+
Create a file at `src/bin/query_account.rs` and add the following code to it:
272271

273272
```rust title="src/bin/query_account.rs"
274-
--8<-- "code/chain-interactions/accounts/query-account/subxt-query-account.rs"
273+
--8<-- "code/chain-interactions/accounts/query-account/subxt/query-account.rs"
275274
```
276275

276+
!!! note
277+
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+
277279
Run the script:
278280

279281
```bash
@@ -282,27 +284,40 @@ Select your preferred SDK below to see complete, runnable examples that query ac
282284

283285
You should see output similar to:
284286

285-
--8<-- "code/chain-interactions/accounts/query-account/subxt-query-account-output.html"
287+
--8<-- "code/chain-interactions/accounts/query-account/subxt/query-account-output.html"
286288

287289
## Understanding Account Data
288290

289291
When querying account information, you'll receive several key fields:
290292

291-
- **Nonce** - the number of transactions sent from this account, used to prevent replay attacks
292-
- **Consumers** - the number of modules depending on this account's existence
293-
- **Providers** - the number of modules providing for this account's existence
294-
- **Sufficients** - the number of modules that allow this account to exist on its own
295-
- **Free Balance** - the transferable balance available for transactions
296-
- **Reserved Balance** - balance that is locked for specific purposes (staking, governance, etc.)
297-
- **Frozen Balance** - balance that cannot be used for transfers but may be used for other operations
293+
- **Nonce**: The number of transactions sent from this account, used to prevent replay attacks.
294+
- **Consumers**: The number of modules depending on this account's existence.
295+
- **Providers**: The number of modules providing for this account's existence.
296+
- **Sufficients**: The number of modules that allow this account to exist on its own.
297+
- **Free Balance**: The transferable balance available for transactions.
298+
- **Reserved Balance**: Balance that is locked for specific purposes (staking, governance, etc.).
299+
- **Frozen Balance**: Balance that cannot be used for transfers but may be used for other operations.
298300

299301
The total balance is the sum of free and reserved balances.
300302

301303
## Where to Go Next
302304

303-
Now that you understand how to query account information, explore these related topics:
305+
<div class="grid cards" markdown>
306+
307+
- <span class="badge guide">Guide</span> **Query On-Chain State**
308+
309+
---
310+
311+
Explore other types of storage queries.
312+
313+
[:octicons-arrow-right-24: Get Started](/chain-interactions/query-data/query-sdks/)
314+
315+
- <span class="badge guide">Guide</span> **Send Transactions**
316+
317+
---
318+
319+
Learn how to construct and submit transactions.
320+
321+
[:octicons-arrow-right-24: Get Started](/chain-interactions/send-transactions/with-sdks/)
304322

305-
- **[Send Transactions with SDKs](/chain-interactions/send-transactions/with-sdks/)** - Learn to construct and submit transactions
306-
- **[Query On-Chain State](/chain-interactions/query-data/query-sdks/)** - Explore other types of storage queries
307-
- **[Calculate Transaction Fees](/chain-interactions/send-transactions/calculate-transaction-fees/)** - Estimate fees before sending transactions
308-
- **[SDK Reference Pages](/reference/tools/)** - Detailed documentation for each SDK
323+
</div>

.chain-interactions/query-data/query-sdks.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ Select your preferred SDK below to see complete, runnable examples that query Po
6161
--8<-- "code/chain-interactions/query-data/query-sdks/papi/query-balance.ts"
6262
```
6363

64-
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.
6566

6667
Run the script:
6768

@@ -83,7 +84,8 @@ Select your preferred SDK below to see complete, runnable examples that query Po
8384
--8<-- "code/chain-interactions/query-data/query-sdks/papi/query-asset.ts"
8485
```
8586

86-
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.
8789

8890
Run the script:
8991

@@ -130,7 +132,8 @@ Select your preferred SDK below to see complete, runnable examples that query Po
130132
--8<-- "code/chain-interactions/query-data/query-sdks/pjs/query-balance.js"
131133
```
132134

133-
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.
134137

135138
Run the script:
136139

@@ -152,8 +155,9 @@ Select your preferred SDK below to see complete, runnable examples that query Po
152155
--8<-- "code/chain-interactions/query-data/query-sdks/pjs/query-asset.js"
153156
```
154157

155-
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+
157161
Run the script:
158162

159163
```bash
@@ -197,7 +201,8 @@ Select your preferred SDK below to see complete, runnable examples that query Po
197201
--8<-- "code/chain-interactions/query-data/query-sdks/dedot/query-balance.ts"
198202
```
199203

200-
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.
201206

202207
Run the script:
203208

@@ -219,7 +224,8 @@ Select your preferred SDK below to see complete, runnable examples that query Po
219224
--8<-- "code/chain-interactions/query-data/query-sdks/dedot/query-asset.ts"
220225
```
221226

222-
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.
223229

224230
Run the script:
225231

@@ -263,7 +269,8 @@ Select your preferred SDK below to see complete, runnable examples that query Po
263269
--8<-- "code/chain-interactions/query-data/query-sdks/psi/query_balance.py"
264270
```
265271

266-
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.
267274

268275
Run the script:
269276

@@ -285,7 +292,8 @@ Select your preferred SDK below to see complete, runnable examples that query Po
285292
--8<-- "code/chain-interactions/query-data/query-sdks/psi/query_asset.py"
286293
```
287294

288-
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.
289297

290298
Run the script:
291299

@@ -326,7 +334,8 @@ Select your preferred SDK below to see complete, runnable examples that query Po
326334
subxt metadata --url INSERT_WS_ENDPOINT -o asset_hub_metadata.scale
327335
```
328336

329-
Ensure to replace `INSERT_WS_ENDPOINT` with the proper WebSocket endpoint, such as `wss://polkadot-asset-hub-rpc.polkadot.io` for Polkadot Hub.
337+
!!! note
338+
Ensure to replace `INSERT_WS_ENDPOINT` with the proper WebSocket endpoint, such as `wss://polkadot-asset-hub-rpc.polkadot.io` for Polkadot Hub.
330339

331340
4. Update `Cargo.toml` with the required dependencies:
332341

@@ -344,7 +353,8 @@ Select your preferred SDK below to see complete, runnable examples that query Po
344353
--8<-- "code/chain-interactions/query-data/query-sdks/subxt/src/bin/query_balance.rs"
345354
```
346355

347-
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.
348358

349359
Run the script:
350360

@@ -369,7 +379,8 @@ Select your preferred SDK below to see complete, runnable examples that query Po
369379
--8<-- "code/chain-interactions/query-data/query-sdks/subxt/src/bin/query_asset.rs"
370380
```
371381

372-
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.
373384

374385
Run the script:
375386

0 commit comments

Comments
 (0)