Skip to content

Commit db0c807

Browse files
committed
update content
1 parent eeea27d commit db0c807

File tree

1 file changed

+41
-54
lines changed

1 file changed

+41
-54
lines changed

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

Lines changed: 41 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,33 @@ This guide demonstrates how to query on-chain storage using the Sidecar REST API
1717
- [curl](https://curl.se/){target=\_blank} or any HTTP client
1818
- Access to a Sidecar instance (public or self-hosted)
1919

20+
## Running Sidecar Locally
21+
22+
For production applications or high-frequency queries, run your own Sidecar instance.
23+
24+
=== "Using npm"
25+
26+
```bash
27+
# Install globally
28+
npm install -g @substrate/api-sidecar
29+
30+
# Run with default settings (connects to ws://127.0.0.1:9944)
31+
substrate-api-sidecar
32+
33+
# Run with custom node URL
34+
SAS_SUBSTRATE_URL=wss://polkadot-asset-hub-rpc.polkadot.io substrate-api-sidecar
35+
```
36+
37+
=== "Using Docker"
38+
39+
```bash
40+
docker run --rm -p 8080:8080 \
41+
-e SAS_SUBSTRATE_URL=wss://polkadot-asset-hub-rpc.polkadot.io \
42+
parity/substrate-api-sidecar
43+
```
44+
45+
Once running, access your local instance at `http://localhost:8080`.
46+
2047
## Public Sidecar Endpoints
2148

2249
Parity provides public Sidecar instances for Polkadot ecosystem chains:
@@ -37,7 +64,7 @@ The `/accounts/{accountId}/balance-info` endpoint returns an account's native to
3764
### Request
3865

3966
```bash
40-
curl -s "https://polkadot-asset-hub-public-sidecar.parity-chains.parity.io/accounts/14E5nqKAp3oAJcmzgZhUD2RcptBeUBScxKHgJKU4HPNcKVf3/balance-info"
67+
curl -s "https://polkadot-asset-hub-public-sidecar.parity-chains.parity.io/accounts/<INSERT_ADDRESS>/balance-info"
4168
```
4269

4370
### Response
@@ -66,10 +93,10 @@ You can query the balance at a specific block height or hash using the `at` quer
6693

6794
```bash
6895
# Query at block height
69-
curl -s "https://polkadot-asset-hub-public-sidecar.parity-chains.parity.io/accounts/14E5nqKAp3oAJcmzgZhUD2RcptBeUBScxKHgJKU4HPNcKVf3/balance-info?at=10000000"
96+
curl -s "https://polkadot-asset-hub-public-sidecar.parity-chains.parity.io/accounts/<INSERT_ADDRESS>/balance-info?at=10000000"
7097

7198
# Query at block hash
72-
curl -s "https://polkadot-asset-hub-public-sidecar.parity-chains.parity.io/accounts/14E5nqKAp3oAJcmzgZhUD2RcptBeUBScxKHgJKU4HPNcKVf3/balance-info?at=0x..."
99+
curl -s "https://polkadot-asset-hub-public-sidecar.parity-chains.parity.io/accounts/<INSERT_ADDRESS>/balance-info?at=0x..."
73100
```
74101

75102
## Query Asset Balances
@@ -79,15 +106,15 @@ The `/accounts/{accountId}/asset-balances` endpoint returns an account's balance
79106
### Request All Asset Balances
80107

81108
```bash
82-
curl -s "https://polkadot-asset-hub-public-sidecar.parity-chains.parity.io/accounts/14E5nqKAp3oAJcmzgZhUD2RcptBeUBScxKHgJKU4HPNcKVf3/asset-balances"
109+
curl -s "https://polkadot-asset-hub-public-sidecar.parity-chains.parity.io/accounts/<INSERT_ADDRESS>/asset-balances"
83110
```
84111

85112
### Request Specific Asset Balance
86113

87114
To query a specific asset (e.g., USDT with asset ID 1984):
88115

89116
```bash
90-
curl -s "https://polkadot-asset-hub-public-sidecar.parity-chains.parity.io/accounts/14E5nqKAp3oAJcmzgZhUD2RcptBeUBScxKHgJKU4HPNcKVf3/asset-balances?assets[]=1984"
117+
curl -s "https://polkadot-asset-hub-public-sidecar.parity-chains.parity.io/accounts/<INSERT_ADDRESS>/asset-balances?assets[]=1984"
91118
```
92119

93120
### Response
@@ -113,7 +140,7 @@ curl -s "https://polkadot-asset-hub-public-sidecar.parity-chains.parity.io/accou
113140
You can query multiple assets in a single request:
114141

115142
```bash
116-
curl -s "https://polkadot-asset-hub-public-sidecar.parity-chains.parity.io/accounts/14E5nqKAp3oAJcmzgZhUD2RcptBeUBScxKHgJKU4HPNcKVf3/asset-balances?assets[]=1984&assets[]=1337"
143+
curl -s "https://polkadot-asset-hub-public-sidecar.parity-chains.parity.io/accounts/<INSERT_ADDRESS>/asset-balances?assets[]=1984&assets[]=1337"
117144
```
118145

119146
## Query Asset Metadata
@@ -168,6 +195,14 @@ curl -s "https://polkadot-asset-hub-public-sidecar.parity-chains.parity.io/palle
168195
| `sufficients` | Number of accounts whose existence is paid for by this asset |
169196
| `status` | Asset status (Live, Frozen, or Destroying) |
170197

198+
## Query Foreign Asset Balances
199+
200+
For cross-chain assets (foreign assets), use the `/accounts/{accountId}/foreign-asset-balances` endpoint:
201+
202+
```bash
203+
curl -s "https://polkadot-asset-hub-public-sidecar.parity-chains.parity.io/accounts/<INSERT_ADDRESS>/foreign-asset-balances"
204+
```
205+
171206
## Query Block Information
172207

173208
The `/blocks/{blockId}` endpoint returns detailed block information including extrinsics and events.
@@ -194,58 +229,10 @@ curl -s "https://polkadot-asset-hub-public-sidecar.parity-chains.parity.io/block
194229
--8<-- "code/chain-interactions/query-data/query-rest/block-response.json"
195230
```
196231

197-
## Query Foreign Asset Balances
198-
199-
For cross-chain assets (foreign assets), use the `/accounts/{accountId}/foreign-asset-balances` endpoint:
200-
201-
```bash
202-
curl -s "https://polkadot-asset-hub-public-sidecar.parity-chains.parity.io/accounts/14E5nqKAp3oAJcmzgZhUD2RcptBeUBScxKHgJKU4HPNcKVf3/foreign-asset-balances"
203-
```
204-
205-
## Running Sidecar Locally
206-
207-
For production applications or high-frequency queries, run your own Sidecar instance.
208-
209-
### Using npm
210-
211-
```bash
212-
# Install globally
213-
npm install -g @substrate/api-sidecar
214-
215-
# Run with default settings (connects to ws://127.0.0.1:9944)
216-
substrate-api-sidecar
217-
218-
# Run with custom node URL
219-
SAS_SUBSTRATE_URL=wss://polkadot-asset-hub-rpc.polkadot.io substrate-api-sidecar
220-
```
221-
222-
### Using Docker
223-
224-
```bash
225-
docker run --rm -p 8080:8080 \
226-
-e SAS_SUBSTRATE_URL=wss://polkadot-asset-hub-rpc.polkadot.io \
227-
parity/substrate-api-sidecar
228-
```
229-
230-
Once running, access your local instance at `http://localhost:8080`.
231-
232232
## API Reference
233233

234234
For a complete list of endpoints and parameters, see the [Sidecar API Documentation](https://paritytech.github.io/substrate-api-sidecar/docsv2/){target=\_blank}.
235235

236-
Common endpoints include:
237-
238-
| Endpoint | Description |
239-
|----------|-------------|
240-
| `/accounts/{accountId}/balance-info` | Native token balance |
241-
| `/accounts/{accountId}/asset-balances` | Assets pallet balances |
242-
| `/accounts/{accountId}/foreign-asset-balances` | Foreign assets balances |
243-
| `/accounts/{accountId}/pool-asset-balances` | Pool asset balances |
244-
| `/blocks/{blockId}` | Block information |
245-
| `/blocks/head` | Latest block |
246-
| `/pallets/{palletId}/storage/{storageItemId}` | Pallet storage queries |
247-
| `/transaction/material` | Transaction construction material |
248-
249236
## Where to Go Next
250237

251238
Now that you understand how to query on-chain state with the REST API, explore these related topics:

0 commit comments

Comments
 (0)