Skip to content

Commit fecdb9b

Browse files
nhussein11eshaben
andauthored
Add rpc calls page (#817)
* fix: adding rpc calls page * fix: update RPC calls documentation to include links for Polkadot.js and Subxt * Apply suggestions from code review Co-authored-by: Erin Shaben <[email protected]> * Enhance RPC calls documentation by restructuring method descriptions, adding parameters, and providing clearer examples for better usability. * Refactor RPC calls documentation to consolidate methods checking section, clarifying usage via curl and Polkadot.Js Apps. --------- Co-authored-by: Erin Shaben <[email protected]>
1 parent 1fcec19 commit fecdb9b

File tree

8 files changed

+404
-0
lines changed

8 files changed

+404
-0
lines changed

develop/toolkit/parachains/.pages

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ nav:
66
- fork-chains
77
- e2e-testing
88
- 'Light Clients': light-clients.md
9+
- 'RPC Calls': rpc-calls.md
910
- 'Polkadot Omni Node': polkadot-omni-node.md
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
---
2+
title: RPC Calls to Polkadot SDK chains.
3+
description: Learn how to interact with Polkadot SDK-based chains using RPC calls. This guide covers essential methods and usage via curl.
4+
---
5+
6+
# RPC Calls
7+
8+
## Introduction
9+
10+
[Remote Procedure Call](https://en.wikipedia.org/wiki/Remote_procedure_call){target=\_blank} (RPC) interfaces are the primary way to interact programmatically with Polkadot SDK-based parachains and relay chains. RPC calls allow you to query chain state, submit transactions, and monitor network health from external applications or scripts.
11+
12+
This guide covers:
13+
14+
- What RPC calls are and how they work in the Polkadot SDK.
15+
- How to make RPC calls using `curl` or similar tools.
16+
- The most useful and commonly used RPC methods.
17+
18+
RPC endpoints are available on every node and can be accessed via HTTP and WebSocket. Most developer tools, dashboards, and libraries (like [Polkadot.js](/develop/toolkit/api-libraries/polkadot-js-api){target=\_blank}, [Subxt](/develop/toolkit/api-libraries/subxt){target=\_blank}, and others) utilize these endpoints internally.
19+
20+
## How Do RPC Calls Work?
21+
22+
RPC (Remote Procedure Call) is a protocol that allows you to invoke functions on a remote server (in this case, a blockchain node) as if they were local. Polkadot SDK nodes implement the [JSON-RPC 2.0](https://www.jsonrpc.org/specification){target=\_blank} standard, making it easy to interact with them using standard HTTP requests.
23+
24+
```mermaid
25+
flowchart LR
26+
CLIENT([Client Application])-- JSON-RPC Request -->NODE([Node])
27+
NODE -- JSON Response --> CLIENT
28+
```
29+
30+
RPC calls are stateless and can be used to:
31+
32+
- Query chain state (e.g., block number, storage values)
33+
- Submit extrinsics (transactions)
34+
- Monitor node and network health
35+
- Retrieve metadata and runtime information
36+
37+
## Making RPC Calls with Curl
38+
39+
You can make RPC calls to a node using [`curl`](https://curl.se/){target=\_blank} or any HTTP client. The general format that the RPC calls stick to is the following:
40+
41+
```bash
42+
curl -H "Content-Type: application/json" \
43+
-d '{"id":1, "jsonrpc":"2.0", "method": "INSERT_METHOD_NAME", "params": [INSERT_PARAMS]}' \
44+
NODE_ENDPOINT
45+
```
46+
47+
- **`method`**: The RPC method you want to call (e.g., `system_health`).
48+
- **`params`**: Parameters for the method (if any).
49+
- **`NODE_ENDPOINT`**: The HTTP endpoint of your node (e.g., `http://localhost:9933` or a public endpoint).
50+
51+
Here's a simple example to get the latest block number of the Polkadot relay chain; you can use the following node endpoint:
52+
53+
```bash
54+
curl -H "Content-Type: application/json" \
55+
-d '{"id":1, "jsonrpc":"2.0", "method": "chain_getBlock"}' \
56+
https://rpc.polkadot.io
57+
```
58+
59+
## Essential RPC Methods
60+
61+
Below are some of the most useful and commonly used RPC methods for Polkadot SDK-based chains. Each method includes a description, parameters, and an example request.
62+
63+
---
64+
65+
### system_health
66+
67+
Checks the health of your node.
68+
69+
**Parameters:**
70+
71+
None
72+
73+
**Example:**
74+
75+
```bash title="system_health"
76+
curl -H "Content-Type: application/json" \
77+
-d '{"id":1, "jsonrpc":"2.0", "method": "system_health", "params":[]}' \
78+
http://localhost:9933
79+
```
80+
81+
---
82+
83+
### chain_getBlock
84+
85+
Returns the latest block or a specific block by hash.
86+
87+
**Parameters:**
88+
89+
- `blockHash` *(optional, string)* – The hash of the block to retrieve. If omitted, returns the latest block.
90+
91+
**Example:**
92+
93+
```bash title="chain_getBlock"
94+
curl -H "Content-Type: application/json" \
95+
-d '{"id":1, "jsonrpc":"2.0", "method": "chain_getBlock", "params":[]}' \
96+
http://localhost:9933
97+
```
98+
99+
---
100+
101+
### state_getStorage
102+
103+
Queries on-chain storage by key (requires [SCALE-encoded](/polkadot-protocol/parachain-basics/data-encoding){target=_blank} storage key).
104+
105+
**Parameters:**
106+
107+
- `storageKey` *(string)* – The SCALE-encoded storage key to query.
108+
109+
**Example:**
110+
111+
```bash title="state_getStorage"
112+
curl -H "Content-Type: application/json" \
113+
-d '{"id":1, "jsonrpc":"2.0", "method": "state_getStorage", "params":["0x..."]}' \
114+
http://localhost:9933
115+
```
116+
117+
---
118+
119+
### author_submitExtrinsic
120+
121+
Submits a signed extrinsic (transaction) to the node.
122+
123+
**Parameters:**
124+
125+
- `extrinsic` *(string)* – The SCALE-encoded, signed extrinsic (transaction).
126+
127+
**Example:**
128+
129+
```bash title="author_submitExtrinsic"
130+
curl -H "Content-Type: application/json" \
131+
-d '{"id":1, "jsonrpc":"2.0", "method": "author_submitExtrinsic", "params":["0x..."]}' \
132+
http://localhost:9933
133+
```
134+
135+
---
136+
137+
### state_getMetadata
138+
139+
Fetches the runtime metadata (needed for decoding storage and extrinsics).
140+
141+
**Parameters:**
142+
143+
None
144+
145+
**Example:**
146+
147+
```bash title="state_getMetadata"
148+
curl -H "Content-Type: application/json" \
149+
-d '{"id":1, "jsonrpc":"2.0", "method": "state_getMetadata", "params":[]}' \
150+
http://localhost:9933
151+
```
152+
153+
---
154+
155+
## Check Available RPC Calls
156+
157+
To check all the RPC methods exposed by your node, you can use the `rpc_methods` call to get a comprehensive list of available methods. This is particularly useful when working with different chain implementations or custom runtimes that may have additional RPC endpoints. You can do this via [`curl`](#using-curl) or the [Polkadot.Js Apps](#using-polkadotjs-apps).
158+
159+
### Using curl
160+
161+
To check the available RPC methods using `curl`, you can use the following command:
162+
163+
```bash
164+
curl -H "Content-Type: application/json" \
165+
-d '{"id":1, "jsonrpc":"2.0", "method": "rpc_methods", "params":[]}' \
166+
https://rpc.polkadot.io
167+
```
168+
169+
You can replace `https://rpc.polkadot.io` with the node endpoint you need to query.
170+
171+
### Using Polkadot.js Apps
172+
173+
1. Go to the [Polkadot.js Apps UI](https://polkadot.js.org/apps){target=\_blank} and navigate to the RPC calls section.
174+
175+
![](/images/develop/toolkit/parachains/rpc-calls/rpc-calls-01.webp)
176+
177+
2. Select **`rpc`** from the dropdown menu.
178+
179+
![](/images/develop/toolkit/parachains/rpc-calls/rpc-calls-02.webp)
180+
181+
3. Choose the **`methods`** method.
182+
183+
![](/images/develop/toolkit/parachains/rpc-calls/rpc-calls-03.webp)
184+
185+
4. Submit the call to get a list of all available RPC methods.
186+
187+
![](/images/develop/toolkit/parachains/rpc-calls/rpc-calls-04.webp)
188+
189+
This will return a JSON response containing all the RPC methods supported by your node.
190+
191+
![](/images/develop/toolkit/parachains/rpc-calls/rpc-calls-05.webp)
192+
193+
From this interface, you can also query the RPC methods directly, as you would do with curl.
194+
195+
## Resources
196+
197+
- [Polkadot JSON-RPC API Reference](https://polkadot.js.org/docs/substrate/rpc/){target=\_blank}
198+
- [Parity DevOps: Important Flags for Running an RPC Node](https://paritytech.github.io/devops-guide/guides/rpc_index.html?#important-flags-for-running-an-rpc-node){target=\_blank}
199+
- [Polkadot.js Apps RPC Explorer](https://polkadot.js.org/apps/#/rpc){target=\_blank}
112 KB
Loading
37.5 KB
Loading
39 KB
Loading
35.9 KB
Loading
66 KB
Loading

0 commit comments

Comments
 (0)