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