Skip to content

Commit fd94d52

Browse files
committed
feat: add Polkadot SDK JSON-RPC methods documentation
1 parent bb20f7e commit fd94d52

File tree

2 files changed

+141
-2
lines changed

2 files changed

+141
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
---
2+
description: Polkadot SDK JSON-RPC Methods
3+
---
4+
5+
# Polkadot SDK
6+
7+
## polkadot_signTransaction
8+
9+
This method returns a signature for the provided transaction payload. It will be signed by the keypair corresponding to the requested signer address.
10+
11+
### Parameters
12+
13+
1. `Object` - Request parameters:
14+
- `address`: `string` - SS58 encoded address of the signer
15+
- `transactionPayload`: `Object` - As per Polkadot type `SignerPayloadJSON` containing:
16+
- `address`: `string` - The SS58 encoded address (must match outer address)
17+
- `assetId`: `HexString | null` - (optional) The id of the asset used to pay fees
18+
- `blockHash`: `HexString` - The checkpoint hash of the block, 32 bytes
19+
- `blockNumber`: `HexString` - The checkpoint block number (hex encoded)
20+
- `era`: `HexString` - The mortality period of this transaction
21+
- `genesisHash`: `HexString` - The genesis hash of the chain, 32 bytes
22+
- `metadataHash`: `HexString | null` - (optional) The hash of the metadata for verification
23+
- `method`: `string` - The SCALE encoded method data (hex encoded)
24+
- `mode`: `number` - (optional) The mode for metadata verification (0=none, 1=exact, 2=partial)
25+
- `nonce`: `HexString` - The nonce for this transaction (hex encoded)
26+
- `specVersion`: `HexString` - The current specification version (hex encoded)
27+
- `tip`: `HexString` - The tip for this transaction (hex encoded amount)
28+
- `transactionVersion`: `HexString` - The current transaction version (hex encoded)
29+
- `signedExtensions`: `string[]` - The array of signed extension identifiers
30+
- `version`: `number` - The extrinsic version number
31+
- `withSignedTransaction`: `boolean` - (optional) Request signed transaction bytes
32+
33+
### Returns
34+
35+
1. `Object` - Signature result:
36+
- `signature`: `string` - hex encoded signature
37+
38+
### Example
39+
40+
```javascript
41+
// Request
42+
{
43+
"id": 1,
44+
"jsonrpc": "2.0",
45+
"method": "polkadot_signTransaction",
46+
"params": {
47+
"address": "15UyNqZ7NB1QQVpY9xv7VGwkxtvXePKihFHx8kH4VgEcS1gU",
48+
"transactionPayload": {
49+
"address": "15UyNqZ7NB1QQVpY9xv7VGwkxtvXePKihFHx8kH4VgEcS1gU",
50+
"assetId": null,
51+
"blockHash": "0x1b1c32a33c3622044a3be1b7753ff9b24695c327fc9254f97c...",
52+
"blockNumber": "0x00000393",
53+
"era": "0x0500",
54+
"genesisHash": "0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3",
55+
"metadataHash": null,
56+
"method": "0x0400....",
57+
"mode": 0,
58+
"nonce": "0x00000000",
59+
"specVersion": "0x00000000",
60+
"tip": "0x00000000000000000000000000000000",
61+
"transactionVersion": "0x00000004",
62+
"signedExtensions": [
63+
"CheckNonZeroSender",
64+
"CheckSpecVersion",
65+
"CheckTxVersion",
66+
"CheckGenesis",
67+
"CheckMortality",
68+
"CheckNonce",
69+
"CheckWeight",
70+
"ChargeTransactionPayment"
71+
],
72+
"version": 4
73+
}
74+
}
75+
}
76+
77+
// Result
78+
{
79+
"id": 1,
80+
"jsonrpc": "2.0",
81+
"result": {
82+
"signature": "0x01234567..."
83+
}
84+
}
85+
```
86+
87+
Note: The `method` field in the transaction payload contains the SCALE encoded call data specific to the transaction being signed. This typically includes the pallet name, function name and any parameters required for that specific transaction.
88+
89+
## polkadot_signMessage
90+
91+
This method returns a signature for the provided message payload. It will be signed by the keypair corresponding to the requested signer address.
92+
93+
### Parameters
94+
95+
1. `Object` - As per Polkadot type `SignerPayloadRaw` containing:
96+
- `address`: `string` - SS58 encoded address
97+
- `data`: `string` - The hex-encoded data for this request
98+
- `type`: `'bytes' | 'payload'` - (optional) Identifies if the message is arbitrary bytes or a transaction payload
99+
100+
:::note
101+
`polkadot_signMessage` can potentially be used to sign arbitrary transactions blindly. To mitigate this security risk:
102+
103+
1. Always wrap messages in `<Bytes>message</Bytes>` tags before hex encoding when message `type` is `'bytes'` or not specified
104+
2. If the type is not `'payload'`, signers MUST verify that messages are properly wrapped
105+
3. Use `type: 'payload'` only when signing transaction-like data that should be possible to decrypt
106+
107+
This convention helps prevent malicious applications from using `polkadot_signMessage` for blind transaction signing while maintaining compatibility with widely-used Polkadot signing implementations.
108+
:::
109+
110+
### Returns
111+
112+
1. `Object` - Signature result:
113+
- `signature`: `string` - hex encoded signature
114+
115+
### Example
116+
117+
```javascript
118+
// Request
119+
{
120+
"id": 1,
121+
"jsonrpc": "2.0",
122+
"method": "polkadot_signMessage",
123+
"params": {
124+
"address": "15UyNqZ7NB1QQVpY9xv7VGwkxtvXePKihFHx8kH4VgEcS1gU",
125+
"data": "0x3c42797465733e68656c6c6f20776f726c643c2f42797465733e", // "<Bytes>hello world</Bytes>" hex encoded
126+
"type": "bytes"
127+
}
128+
}
129+
130+
// Result
131+
{
132+
"id": 1,
133+
"jsonrpc": "2.0",
134+
"result": {
135+
"signature": "0x6a98517e159dcaef1855cda5f5e5a61387ac3b63212b0f82642f5599502fc9eb1ea134e2db5dfbe0ec4530c6e7e576b177ad0618f68eaec37a3ac6dce819a30a"
136+
}
137+
}
138+
```

sidebars.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ const advanced = {
4848
type: 'category',
4949
label: 'RPC Reference',
5050
items: [
51-
'advanced/multichain/rpc-reference/cosmos-rpc',
5251
'advanced/multichain/rpc-reference/ethereum-rpc',
5352
'advanced/multichain/rpc-reference/solana-rpc',
53+
'advanced/multichain/rpc-reference/polkadot-sdk-rpc',
54+
'advanced/multichain/rpc-reference/cosmos-rpc',
5455
'advanced/multichain/rpc-reference/near-rpc',
5556
'advanced/multichain/rpc-reference/starknet-rpc',
5657
'advanced/multichain/rpc-reference/stellar-rpc',
@@ -1270,4 +1271,4 @@ module.exports = {
12701271
specs,
12711272
dropdown_placeholder
12721273
]
1273-
}
1274+
}

0 commit comments

Comments
 (0)