You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -7,7 +7,7 @@ description: Understand how to construct, sign, and broadcast transactions in th
7
7
8
8
## Introduction
9
9
10
-
This page will discuss the transaction format in Polkadot and how to create, sign, and broadcast transactions. Like the other pages in this guide, this page demonstrates some of the available tools.
10
+
This page will discuss the transaction format in Polkadot and how to create, sign, and broadcast transactions as well as highlight some of commands and tools available for integrators.
11
11
12
12
**Always refer to each tool's documentation when integrating.**
13
13
@@ -77,45 +77,104 @@ The typical transaction workflow is as follows:
77
77
4. Serialize the signed payload into a transaction.
78
78
5. Submit the serialized transaction.
79
79
80
-
Parity provides the following tools to help perform these steps.
80
+
Parity provides several tools to help perform these steps.
81
81
82
82
## Polkadot-JS Tools
83
83
84
84
[Polkadot-JS Tools](https://github.com/polkadot-js/tools){target=\_blank} contains a set of command line tools for
85
-
interacting with a Substrate client, including one called "Signer CLI" to create, sign, and
85
+
interacting with a Polkadot SDK client, including one called "Signer CLI" to create, sign, and
86
86
broadcast transactions.
87
87
88
+
!!!note "Generating SS58 Addresses"
89
+
For the examples on this page, it may be helpful to generate new accounts for signing purposes.
90
+
For this, you can use the [Subkey](/polkadot-protocol/basics/accounts/#using-subkey){target=\_blank} CLI tool.
### Creating a Transaction, Signing, and Submitting
141
+
142
+
For example, let's send 0.5 DOT from `121X5bEgTZcGQx5NZjwuTjqqKoiG8B2wEAvrUFjuw24ZGZf2` to `15vrtLsCQFG3qRYUcaEeeEih4JwepocNJHkpsrqojqnZPc2y` using `polkadot-js-signer`.
143
+
144
+
First we call submit to create the transaction and give us the payload to sign:
This will output the signature of the transaction:
164
+
```
165
+
Signature: 0xe6facf194a8e...413ce3155c2d1240b
115
166
```
116
167
117
-
Save the output and bring it to the machine that you will broadcast from, enter it into `submit`'s
118
-
signature field, and send the transaction (or just return the serialized transaction if using `sendOffline`).
168
+
Paste this signature into the `submit`'s signature field, and send the transaction (or just return the serialized transaction if using `sendOffline`).
169
+
170
+
By default, submit will create a mortal extrinsic with a lifetime of 50 blocks.
171
+
Assuming a six-second block time, you will have five minutes to go offline, sign the transaction, paste the signature, and submit the signed transaction.
172
+
173
+
!!!note "Submitting Pre-Signed Transaction"
174
+
You can also submit pre-signed transactions, e.g. generated using the `sendOffline` command.
We should get a Polkadot network running on port 9944.
197
+
198
+
Next we will use the [`TxWrapper example script`](https://github.com/paritytech/txwrapper-core/blob/main/packages/txwrapper-examples/polkadot/src/polkadot.ts){target=\_blank} to create and sign transactions.
199
+
200
+
For this we will need the [`TxWrapper`](https://github.com/paritytech/txwrapper-core){target=\_blank} library. Let's clone [`TxWrapper`](https://github.com/paritytech/txwrapper-core){target=\_blank}:
Build and run the [`TxWrapper Polkadot example script`](https://github.com/paritytech/txwrapper-core/blob/main/packages/txwrapper-examples/polkadot/src/polkadot.ts){target=\_blank}:
To: 14E5nqKAp3oAJcmzgZhUD2RcptBeUBScxKHgJKU4HPNcKVf3
221
+
Amount: "10000000000"
222
+
223
+
Payload to Sign: 0xa40503008eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a480700e40b54028500000000b1590f001a00000091b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3843125cd049613a7edf44b55a01efbabffcd1b962068a82070cff82314b67bbc00
224
+
225
+
Decoded Transaction
226
+
To: 14E5nqKAp3oAJcmzgZhUD2RcptBeUBScxKHgJKU4HPNcKVf3
Transaction to Submit: 0x45028400d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d01ae703e667b3b444e3613a5f06d16bedf2460a18e52075b47c6442ebc1d316917c6d12e3aa7bbd2f8db76cc859b43134cecb4495613d8d504901de776d0642b8285000000000503008eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a480700e40b5402
Actual Tx Hash: 0xa12126a095b38f0c70331be78743329a851e33839f9b2f93a7ecc34541507891
235
+
236
+
Decoded Transaction
237
+
To: 14E5nqKAp3oAJcmzgZhUD2RcptBeUBScxKHgJKU4HPNcKVf3
238
+
Amount: "10000000000"
239
+
```
240
+
241
+
The [`TxWrapper example script`](https://github.com/paritytech/txwrapper-core/blob/main/packages/txwrapper-examples/polkadot/src/polkadot.ts){target=\_blank} includes many of the reference examples below:
242
+
129
243
**Import a private key**
130
244
131
245
```ts
@@ -219,33 +333,6 @@ import { getTxHash } from ‘@substrate/txwrapper-polkadot’;
219
333
const txHash =getTxHash(signedTx);
220
334
```
221
335
222
-
## Submitting a Signed Payload
223
-
224
-
There are several ways to submit a signed payload:
Other than Polkadot JS Tools and TXWrapper, there are several other libraries that can also be used to submit a signed payload such as the [Sidecar API](/develop/toolkit/api-libraries/sidecar/#sidecar-api){target=\_blank} or using RPC calls with `author_submitExtrinsic` or `author_submitAndWatchExtrinsic`, the latter of which will subscribe you to events to be notified as a transaction gets validated and included in the chain. You can see all the available libraries in the [API Libraries](/develop/toolkit/api-libraries/) section of the Polkadot Docs.
0 commit comments