Skip to content

Commit 36bcc66

Browse files
committed
formatting updates
1 parent 9fa46b2 commit 36bcc66

File tree

7 files changed

+83
-77
lines changed

7 files changed

+83
-77
lines changed

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

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,22 @@ categories: Chain Interactions
88

99
## Introduction
1010

11-
Polkadot SDK-based blockchains store data in a key-value database that can be queried by external applications. This on-chain state includes account balances, asset information, governance proposals, and any other data the runtime manages.
11+
Polkadot SDK-based blockchains store data in a key-value database that external applications can query. This on-chain state includes account balances, asset information, governance proposals, and any other data the runtime manages.
1212

1313
This guide demonstrates how to query on-chain storage 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 Polkadot Hub for account balances and asset information.
2222

2323
## Query On-Chain Data
2424

2525
=== "PAPI"
2626

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

3129
- [Node.js](https://nodejs.org/){target=\_blank} v18 or higher
@@ -57,7 +55,7 @@ Select your preferred SDK below to see complete, runnable examples that query Po
5755

5856
The following example queries the `System.Account` storage to retrieve an account's native token balance.
5957

60-
Create a file named `query-balance.ts`:
58+
Create a file named `query-balance.ts` and add the following code to it:
6159

6260
```typescript title="query-balance.ts"
6361
--8<-- "code/chain-interactions/query-data/query-sdks/papi/query-balance.ts"
@@ -79,7 +77,7 @@ Select your preferred SDK below to see complete, runnable examples that query Po
7977

8078
The following example queries the `Assets` pallet to retrieve metadata and balance information for USDT (asset ID 1984).
8179

82-
Create a file named `query-asset.ts`:
80+
Create a file named `query-asset.ts` and add the following code to it:
8381

8482
```typescript title="query-asset.ts"
8583
--8<-- "code/chain-interactions/query-data/query-sdks/papi/query-asset.ts"
@@ -102,8 +100,6 @@ Select your preferred SDK below to see complete, runnable examples that query Po
102100
!!! warning "Maintenance Mode Only"
103101
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.
104102

105-
[Polkadot.js API](/reference/tools/polkadot-js-api/){target=\_blank} is a comprehensive JavaScript library with extensive ecosystem support.
106-
107103
**Prerequisites**
108104

109105
- [Node.js](https://nodejs.org/){target=\_blank} v18 or higher
@@ -128,7 +124,7 @@ Select your preferred SDK below to see complete, runnable examples that query Po
128124

129125
The following example queries the `System.Account` storage to retrieve an account's native token balance.
130126

131-
Create a file named `query-balance.js`:
127+
Create a file named `query-balance.js` and add the following code to it:
132128

133129
```javascript title="query-balance.js"
134130
--8<-- "code/chain-interactions/query-data/query-sdks/pjs/query-balance.js"
@@ -150,7 +146,7 @@ Select your preferred SDK below to see complete, runnable examples that query Po
150146

151147
The following example queries the `Assets` pallet to retrieve metadata and balance information for USDT (asset ID 1984).
152148

153-
Create a file named `query-asset.js`:
149+
Create a file named `query-asset.js` and add the following code to it:
154150

155151
```javascript title="query-asset.js"
156152
--8<-- "code/chain-interactions/query-data/query-sdks/pjs/query-asset.js"
@@ -170,8 +166,6 @@ Select your preferred SDK below to see complete, runnable examples that query Po
170166

171167
=== "Dedot"
172168

173-
[Dedot](/reference/tools/dedot/){target=\_blank} is a next-generation TypeScript client that's lightweight, tree-shakable, and maintains API compatibility with Polkadot.js.
174-
175169
**Prerequisites**
176170

177171
- [Node.js](https://nodejs.org/){target=\_blank} v18 or higher
@@ -197,7 +191,7 @@ Select your preferred SDK below to see complete, runnable examples that query Po
197191

198192
The following example queries the `System.Account` storage to retrieve an account's native token balance.
199193

200-
Create a file named `query-balance.ts`:
194+
Create a file named `query-balance.ts` and add the following code to it:
201195

202196
```typescript title="query-balance.ts"
203197
--8<-- "code/chain-interactions/query-data/query-sdks/dedot/query-balance.ts"
@@ -219,7 +213,7 @@ Select your preferred SDK below to see complete, runnable examples that query Po
219213

220214
The following example queries the `Assets` pallet to retrieve metadata and balance information for USDT (asset ID 1984).
221215

222-
Create a file named `query-asset.ts`:
216+
Create a file named `query-asset.ts` and add the following code to it:
223217

224218
```typescript title="query-asset.ts"
225219
--8<-- "code/chain-interactions/query-data/query-sdks/dedot/query-asset.ts"
@@ -237,9 +231,7 @@ Select your preferred SDK below to see complete, runnable examples that query Po
237231

238232
--8<-- 'code/chain-interactions/query-data/query-sdks/dedot/query-asset-ts.html'
239233

240-
=== "Python"
241-
242-
[Python Substrate Interface](/reference/tools/py-substrate-interface/){target=\_blank} provides a Python library for interacting with Substrate-based chains.
234+
=== "Py Substrate Interface"
243235

244236
**Prerequisites**
245237

@@ -265,7 +257,7 @@ Select your preferred SDK below to see complete, runnable examples that query Po
265257

266258
The following example queries the `System.Account` storage to retrieve an account's native token balance.
267259

268-
Create a file named `query_balance.py`:
260+
Create a file named `query_balance.py` and add the following code to it:
269261

270262
```python title="query_balance.py"
271263
--8<-- "code/chain-interactions/query-data/query-sdks/psi/query_balance.py"
@@ -287,7 +279,7 @@ Select your preferred SDK below to see complete, runnable examples that query Po
287279

288280
The following example queries the `Assets` pallet to retrieve metadata and balance information for USDT (asset ID 1984).
289281

290-
Create a file named `query_asset.py`:
282+
Create a file named `query_asset.py` and add the following code to it:
291283

292284
```python title="query_asset.py"
293285
--8<-- "code/chain-interactions/query-data/query-sdks/psi/query_asset.py"
@@ -346,7 +338,7 @@ Select your preferred SDK below to see complete, runnable examples that query Po
346338

347339
The following example queries the `System.Account` storage to retrieve an account's native token balance.
348340

349-
Create a file at `src/bin/query_balance.rs`:
341+
Create a file at `src/bin/query_balance.rs` and add the following code to it:
350342

351343
```rust title="src/bin/query_balance.rs"
352344
--8<-- "code/chain-interactions/query-data/query-sdks/subxt/src/bin/query_balance.rs"
@@ -371,7 +363,7 @@ Select your preferred SDK below to see complete, runnable examples that query Po
371363

372364
The following example queries the `Assets` pallet to retrieve metadata and balance information for USDT (asset ID 1984).
373365

374-
Create a file at `src/bin/query_asset.rs`:
366+
Create a file at `src/bin/query_asset.rs` and add the following code to it:
375367

376368
```rust title="src/bin/query_asset.rs"
377369
--8<-- "code/chain-interactions/query-data/query-sdks/subxt/src/bin/query_asset.rs"
@@ -391,8 +383,22 @@ Select your preferred SDK below to see complete, runnable examples that query Po
391383

392384
## Where to Go Next
393385

394-
Now that you understand how to query on-chain state, explore these related topics:
386+
<div class="grid cards" markdown>
387+
388+
- <span class="badge guide">Guide</span> **Runtime API Calls**
389+
390+
---
391+
392+
Execute runtime APIs for specialized queries.
393+
394+
[:octicons-arrow-right-24: Get Started](/chain-interactions/query-data/runtime-api-calls/)
395+
396+
- <span class="badge guide">Guide</span> **Send Transactions**
397+
398+
---
399+
400+
Learn how to construct and submit transactions.
401+
402+
[:octicons-arrow-right-24: Get Started](/chain-interactions/send-transactions/with-sdks/)
395403

396-
- **[Runtime API Calls](/chain-interactions/query-data/runtime-api-calls/)** - Execute runtime APIs for specialized queries
397-
- **[Send Transactions](/chain-interactions/send-transactions/with-sdks/)** - Learn to construct and submit transactions
398-
- **[SDK Reference Pages](/reference/tools/papi/)** - Detailed documentation for each SDK
404+
</div>

.snippets/code/chain-interactions/query-data/query-sdks/dedot/query-asset.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
import { DedotClient, WsProvider } from "dedot";
2-
import { hexToString } from "dedot/utils";
3-
import type { PolkadotAssetHubApi } from "@dedot/chaintypes";
1+
import { DedotClient, WsProvider } from 'dedot';
2+
import { hexToString } from 'dedot/utils';
3+
import type { PolkadotAssetHubApi } from '@dedot/chaintypes';
44

5-
const ASSET_HUB_RPC = "INSERT_WS_ENDPOINT";
5+
const ASSET_HUB_RPC = 'INSERT_WS_ENDPOINT';
66

77
// USDT on Polkadot Hub
88
const USDT_ASSET_ID = 1984;
99

1010
// Example address to query asset balance
11-
const ADDRESS = "INSERT_ADDRESS";
11+
const ADDRESS = 'INSERT_ADDRESS';
1212

1313
async function main() {
1414
// Initialize provider and client with Asset Hub types
1515
const provider = new WsProvider(ASSET_HUB_RPC);
1616
const client = await DedotClient.new<PolkadotAssetHubApi>(provider);
1717

18-
console.log("Connected to Polkadot Hub");
18+
console.log('Connected to Polkadot Hub');
1919
console.log(`Querying asset ID: ${USDT_ASSET_ID}\n`);
2020

2121
// Query asset metadata
2222
const assetMetadata = await client.query.assets.metadata(USDT_ASSET_ID);
2323

24-
console.log("Asset Metadata:");
24+
console.log('Asset Metadata:');
2525
console.log(` Name: ${hexToString(assetMetadata.name)}`);
2626
console.log(` Symbol: ${hexToString(assetMetadata.symbol)}`);
2727
console.log(` Decimals: ${assetMetadata.decimals}`);
@@ -30,7 +30,7 @@ async function main() {
3030
const assetDetails = await client.query.assets.asset(USDT_ASSET_ID);
3131

3232
if (assetDetails) {
33-
console.log("\nAsset Details:");
33+
console.log('\nAsset Details:');
3434
console.log(` Owner: ${assetDetails.owner.address()}`);
3535
console.log(` Supply: ${assetDetails.supply}`);
3636
console.log(` Accounts: ${assetDetails.accounts}`);
@@ -46,11 +46,11 @@ async function main() {
4646
]);
4747

4848
if (assetAccount) {
49-
console.log("\nAsset Account:");
49+
console.log('\nAsset Account:');
5050
console.log(` Balance: ${assetAccount.balance}`);
5151
console.log(` Status: ${JSON.stringify(assetAccount.status)}`);
5252
} else {
53-
console.log("\nNo asset balance found for this account");
53+
console.log('\nNo asset balance found for this account');
5454
}
5555

5656
// Disconnect the client

.snippets/code/chain-interactions/query-data/query-sdks/dedot/query-balance.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import { DedotClient, WsProvider } from "dedot";
2-
import type { PolkadotAssetHubApi } from "@dedot/chaintypes";
1+
import { DedotClient, WsProvider } from 'dedot';
2+
import type { PolkadotAssetHubApi } from '@dedot/chaintypes';
33

4-
const ASSET_HUB_RPC = "INSERT_WS_ENDPOINT";
4+
const ASSET_HUB_RPC = 'INSERT_WS_ENDPOINT';
55

66
// Example address to query (Polkadot Hub address)
7-
const ADDRESS = "INSERT_ADDRESS";
7+
const ADDRESS = 'INSERT_ADDRESS';
88

99
async function main() {
1010
// Initialize provider and client with Asset Hub types
1111
const provider = new WsProvider(ASSET_HUB_RPC);
1212
const client = await DedotClient.new<PolkadotAssetHubApi>(provider);
1313

14-
console.log("Connected to Polkadot Hub");
14+
console.log('Connected to Polkadot Hub');
1515
console.log(`Querying balance for: ${ADDRESS}\n`);
1616

1717
// Query the system.account storage
@@ -21,7 +21,7 @@ async function main() {
2121
const { nonce, data } = accountInfo;
2222
const { free, reserved, frozen } = data;
2323

24-
console.log("Account Information:");
24+
console.log('Account Information:');
2525
console.log(` Nonce: ${nonce}`);
2626
console.log(` Free Balance: ${free}`);
2727
console.log(` Reserved: ${reserved}`);

.snippets/code/chain-interactions/query-data/query-sdks/papi/query-asset.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { createClient } from "polkadot-api";
2-
import { getWsProvider } from "polkadot-api/ws-provider/node";
3-
import { withPolkadotSdkCompat } from "polkadot-api/polkadot-sdk-compat";
4-
import { pah } from "@polkadot-api/descriptors";
1+
import { createClient } from 'polkadot-api';
2+
import { getWsProvider } from 'polkadot-api/ws-provider/node';
3+
import { withPolkadotSdkCompat } from 'polkadot-api/polkadot-sdk-compat';
4+
import { pah } from '@polkadot-api/descriptors';
55

6-
const ASSET_HUB_RPC = "INSERT_WS_ENDPOINT";
6+
const ASSET_HUB_RPC = 'INSERT_WS_ENDPOINT';
77

88
// USDT on Polkadot Hub
99
const USDT_ASSET_ID = 1984;
1010

1111
// Example address to query asset balance
12-
const ADDRESS = "INSERT_ADDRESS";
12+
const ADDRESS = 'INSERT_ADDRESS';
1313

1414
async function main() {
1515
// Create the client connection
@@ -20,14 +20,14 @@ async function main() {
2020
// Get the typed API for Polkadot Hub
2121
const api = client.getTypedApi(pah);
2222

23-
console.log("Connected to Polkadot Hub");
23+
console.log('Connected to Polkadot Hub');
2424
console.log(`Querying asset ID: ${USDT_ASSET_ID}\n`);
2525

2626
// Query asset metadata
2727
const assetMetadata = await api.query.Assets.Metadata.getValue(USDT_ASSET_ID);
2828

2929
if (assetMetadata) {
30-
console.log("Asset Metadata:");
30+
console.log('Asset Metadata:');
3131
console.log(` Name: ${assetMetadata.name.asText()}`);
3232
console.log(` Symbol: ${assetMetadata.symbol.asText()}`);
3333
console.log(` Decimals: ${assetMetadata.decimals}`);
@@ -37,7 +37,7 @@ async function main() {
3737
const assetDetails = await api.query.Assets.Asset.getValue(USDT_ASSET_ID);
3838

3939
if (assetDetails) {
40-
console.log("\nAsset Details:");
40+
console.log('\nAsset Details:');
4141
console.log(` Owner: ${assetDetails.owner}`);
4242
console.log(` Supply: ${assetDetails.supply}`);
4343
console.log(` Accounts: ${assetDetails.accounts}`);
@@ -53,11 +53,11 @@ async function main() {
5353
);
5454

5555
if (assetAccount) {
56-
console.log("\nAsset Account:");
56+
console.log('\nAsset Account:');
5757
console.log(` Balance: ${assetAccount.balance}`);
5858
console.log(` Status: ${assetAccount.status.type}`);
5959
} else {
60-
console.log("\nNo asset balance found for this account");
60+
console.log('\nNo asset balance found for this account');
6161
}
6262

6363
// Disconnect the client

.snippets/code/chain-interactions/query-data/query-sdks/papi/query-balance.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { createClient } from "polkadot-api";
2-
import { getWsProvider } from "polkadot-api/ws-provider/node";
3-
import { withPolkadotSdkCompat } from "polkadot-api/polkadot-sdk-compat";
4-
import { pah } from "@polkadot-api/descriptors";
1+
import { createClient } from 'polkadot-api';
2+
import { getWsProvider } from 'polkadot-api/ws-provider/node';
3+
import { withPolkadotSdkCompat } from 'polkadot-api/polkadot-sdk-compat';
4+
import { pah } from '@polkadot-api/descriptors';
55

6-
const ASSET_HUB_RPC = "INSERT_WS_ENDPOINT";
6+
const ASSET_HUB_RPC = 'INSERT_WS_ENDPOINT';
77

88
// Example address to query (Polkadot Hub address)
9-
const ADDRESS = "INSERT_ADDRESS";
9+
const ADDRESS = 'INSERT_ADDRESS';
1010

1111
async function main() {
1212
// Create the client connection
@@ -17,7 +17,7 @@ async function main() {
1717
// Get the typed API for Polkadot Hub
1818
const api = client.getTypedApi(pah);
1919

20-
console.log("Connected to Polkadot Hub");
20+
console.log('Connected to Polkadot Hub');
2121
console.log(`Querying balance for: ${ADDRESS}\n`);
2222

2323
// Query the System.Account storage
@@ -27,7 +27,7 @@ async function main() {
2727
const { data, nonce } = accountInfo;
2828
const { free, reserved, frozen } = data;
2929

30-
console.log("Account Information:");
30+
console.log('Account Information:');
3131
console.log(` Nonce: ${nonce}`);
3232
console.log(` Free Balance: ${free}`);
3333
console.log(` Reserved: ${reserved}`);

0 commit comments

Comments
 (0)