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
Copy file name to clipboardExpand all lines: develop/toolkit/integrations/transaction-construction.md
+33-60Lines changed: 33 additions & 60 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,55 +17,38 @@ For further reading, refer to [blocks, transactions, and fees](/polkadot-protoco
17
17
18
18
Polkadot has some basic transaction information that is common to all transactions.
19
19
20
-
- Address: The [SS58-encoded address](/polkadot-protocol/glossary/#ss58-address-format){target=\_blank} of the sending account.
21
-
- Block Hash: The hash of the [checkpoint](/polkadot-protocol/parachain-basics/blocks-transactions-fees/transactions/#transaction-mortality){target=\_blank} block.
22
-
- Block Number: The number of the checkpoint block.
23
-
- Genesis Hash: The genesis hash of the chain.
24
-
- Metadata: The [SCALE-encoded metadata](polkadot-protocol/parachain-basics/data-encoding/){target=\_blank} for the runtime when submitted.
25
-
- Nonce: The nonce for this transaction.
26
-
- Spec Version: The current spec version for the runtime.
27
-
- Transaction Version: The current version for transaction format.
28
-
- Tip: Optional, the [tip](https://docs.polkadot.com/polkadot-protocol/parachain-basics/blocks-transactions-fees/fees/#how-fees-are-calculated){target=\_blank} to increase transaction priority.
29
-
- Mode: The flag indicating whether to verify the metadata hash or not.
30
-
- Era Period: Optional, the number of blocks after the checkpoint for which a transaction is valid.
31
-
If zero, the transaction is [immortal](/polkadot-protocol/parachain-basics/blocks-transactions-fees/transactions/#transaction-mortality){target=\_blank}
32
-
- MetadataHash: Optional, the metadata hash which should match the RUNTIME_METADATA_HASH environment
33
-
variable.
20
+
-**Address**: The [SS58-encoded address](/polkadot-protocol/glossary/#ss58-address-format){target=\_blank} of the sending account.
21
+
-**Block Hash**: The hash of the [checkpoint](/polkadot-protocol/parachain-basics/blocks-transactions-fees/transactions/#transaction-mortality){target=\_blank} block.
22
+
-**Block Number**: The number of the checkpoint block.
23
+
-**Genesis Hash**: The genesis hash of the chain.
24
+
-**Metadata**: The [SCALE-encoded metadata](polkadot-protocol/parachain-basics/data-encoding/){target=\_blank} for the runtime when submitted.
25
+
-**Nonce**: The nonce for this transaction.
26
+
-**Spec Version**: The current spec version for the runtime.
27
+
-**Transaction Version**: The current version for transaction format.
28
+
-**Tip**: Optional, the [tip](https://docs.polkadot.com/polkadot-protocol/parachain-basics/blocks-transactions-fees/fees/#how-fees-are-calculated){target=\_blank} to increase transaction priority.
29
+
-**Mode**: The flag indicating whether to verify the metadata hash or not.
30
+
-**Era Period**: Optional, the number of blocks after the checkpoint for which a transaction is valid. If zero, the transaction is [immortal](/polkadot-protocol/parachain-basics/blocks-transactions-fees/transactions/#transaction-mortality){target=\_blank}
31
+
-**MetadataHash**: Optional, the metadata hash which should match the [`RUNTIME_METADATA_HASH`](https://paritytech.github.io/polkadot-sdk/master/frame_metadata_hash_extension/struct.CheckMetadataHash.html){target=\_blank} environment variable.
34
32
35
33
!!!warning
36
-
There are risks to making a transaction immortal. If an account is reaped and a user re-funds the
37
-
account, then they could replay an immortal transaction. Always default to using a mortal extrinsic.
34
+
There are risks to making a transaction immortal. If an account is reaped and a user re-funds the account, then they could replay an immortal transaction. Always default to using a mortal extrinsic.
38
35
39
-
The nonce queried from the System module does not account for pending transactions. You must track
40
-
and increment the nonce manually if you want to submit multiple valid transactions at the same time.
36
+
The nonce queried from the System module does not account for pending transactions. You must track and increment the nonce manually if you want to submit multiple valid transactions at the same time.
41
37
42
-
Each transaction will have its own (or no) parameters to add. For example, the [`transferKeepAlive`](https://paritytech.github.io/polkadot-sdk/master/pallet_balances/pallet/enum.Call.html#variant.transfer_keep_alive){target=\_blank}
43
-
function from the Balances pallet will take:
38
+
Each transaction will have its own (or no) parameters to add. For example, the [`transferKeepAlive`](https://paritytech.github.io/polkadot-sdk/master/pallet_balances/pallet/enum.Call.html#variant.transfer_keep_alive){target=\_blank} function from the [Balances pallet](https://paritytech.github.io/polkadot-sdk/master/pallet_balances/index.html){target=\_blank} will take:
44
39
45
40
-`dest`: Destination address
46
41
-`#[compact] value`: Number of tokens (compact encoding)
47
42
48
-
Refer to [the protocol specifications](https://spec.polkadot.network/id-extrinsics){target=\_blank}, for the
49
-
concrete specifications and types to build a transaction.
43
+
Refer to [the protocol specifications](https://spec.polkadot.network/id-extrinsics){target=\_blank}, for the concrete specifications and types to build a transaction.
50
44
51
45
**Mode and MetadataHash**
52
46
53
-
The mode and metadataHash fields were introduced in transaction construction to support the optional
54
-
[`CheckMetadataHash` Signed Extension](https://github.com/polkadot-fellows/RFCs/blob/main/text/0078-merkleized-metadata.md){target=\_blank}.
55
-
This enables trustless metadata verification by allowing the chain to verify the correctness of the
56
-
metadata used without the need of a trusted party. This functionality was included in
57
-
[v1.2.5](https://github.com/polkadot-fellows/runtimes/releases/tag/v1.2.5){target=\_blank} runtime release by the
58
-
Fellowship. A user may opt out of this functionality by setting the mode to `0`. When the mode is 00,
59
-
the `metadataHash` field is empty/None.
47
+
The [`mode`](https://paritytech.github.io/polkadot-sdk/master/polkadot_sdk_docs/guides/enable_metadata_hash/index.html){target=\_blank} and [`metadataHash`](https://paritytech.github.io/polkadot-sdk/master/polkadot_sdk_docs/guides/enable_metadata_hash/index.html){target=\_blank} fields were introduced in transaction construction to support the optional [`CheckMetadataHash` Signed Extension](https://github.com/polkadot-fellows/RFCs/blob/main/text/0078-merkleized-metadata.md){target=\_blank}. This enables trustless metadata verification by allowing the chain to verify the correctness of the metadata used without the need of a trusted party. This functionality was included in [v1.2.5](https://github.com/polkadot-fellows/runtimes/releases/tag/v1.2.5){target=\_blank} runtime release by the [Fellowship](https://github.com/polkadot-fellows/manifesto){target=\_blank}. A user may opt out of this functionality by setting the `mode` to `0`. When the mode is 00, the [`metadataHash`](https://paritytech.github.io/polkadot-sdk/master/polkadot_sdk_docs/guides/enable_metadata_hash/index.html){target=\_blank} field is empty/`None`.
60
48
61
49
**Serialized transactions and metadata**
62
50
63
-
Before being submitted, transactions are serialized. Serialized transactions are hex encoded
64
-
SCALE-encoded bytes. The relay chain runtimes are upgradable and therefore any interfaces are
65
-
subject to change, the metadata allows developers to structure any extrinsics or storage entries
66
-
accordingly. The metadata provides you with all of the information required to know how to construct
67
-
the serialized call data specific to your transaction. You can read more about the metadata, its
68
-
format and how to get it in the [Subxt documentation](/polkadot-protocol/parachain-basics/chain-data/#use-subxt){target=\_blank}.
51
+
Before being submitted, transactions are serialized. Serialized transactions are hex encoded SCALE-encoded bytes. The relay chain runtimes are upgradable and therefore any interfaces are subject to change, the metadata allows developers to structure any extrinsics or storage entries accordingly. The metadata provides you with all of the information required to know how to construct the serialized call data specific to your transaction. You can read more about the metadata, its format and how to get it in the [Subxt documentation](/polkadot-protocol/parachain-basics/chain-data/#use-subxt){target=\_blank}.
69
52
70
53
**Transaction Flow**
71
54
@@ -81,23 +64,18 @@ Parity provides several tools to help perform these steps.
81
64
82
65
## Polkadot-JS Tools
83
66
84
-
[Polkadot-JS Tools](https://github.com/polkadot-js/tools){target=\_blank} contains a set of command line tools for
85
-
interacting with a Polkadot SDK client, including one called "Signer CLI" to create, sign, and
86
-
broadcast transactions.
67
+
[Polkadot-JS Tools](https://github.com/polkadot-js/tools){target=\_blank} contains a set of command line tools for interacting with a Polkadot SDK client, including one called "Signer CLI" to create, sign, and broadcast transactions.
87
68
88
-
This example will use the `signer submit` command, which will create and submit the transaction. The
89
-
`signer sendOffline` command has the exact same API, but will not broadcast the transaction.
90
-
`submit` and `sendOffline` must be connected to a node to fetch the current metadata and construct a
91
-
valid transaction.
69
+
This example will use the `signer submit` command, which will create and submit the transaction. The `signer sendOffline` command has the exact same API, but will not broadcast the transaction. `submit` and `sendOffline` must be connected to a node to fetch the current metadata and construct a valid transaction.
92
70
93
-
Start by installing the Signer CLI:
71
+
Start by installing the Signer CLI.
94
72
95
73
```bash
96
74
npm install -g @polkadot/signer-cli
97
75
```
98
76
99
77
To create a transaction, you need to connect to a chain, enabling the creation of a transaction using the chain's metadata.
If you do not want to use the CLI for signing operations, Parity provides an SDK called [txwrapper-core](https://github.com/paritytech/txwrapper-core){target=\_blank} to generate and sign transactions offline. For Polkadot, Kusama, and select parachains, use the `txwrapper-polkadot` package. Other Substrate-based chains will have their own `txwrapper-{chain}` implementations. See the [examples](https://github.com/paritytech/txwrapper-core/blob/main/packages/txwrapper-examples/README.md){target=\_blank} for a guide.
361
334
362
335
### Creating a Transaction, Signing, and Submitting
You should get a Polkadot network running on port 9944.
371
344
372
-
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.
345
+
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.
373
346
374
-
For this you 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}:
347
+
For this you 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}:
356
+
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}:
384
357
```
385
358
yarn run build
386
359
yarn run polkadot
@@ -412,8 +385,8 @@ Decoded Transaction
412
385
Amount: "10000000000"
413
386
```
414
387
415
-
The [`TxWrapper example script`](https://github.com/paritytech/txwrapper-core/blob/main/packages/txwrapper-examples/polkadot/src/polkadot.ts){target=\_blank} includes several reference examples.
388
+
The [`txwrapper example script`](https://github.com/paritytech/txwrapper-core/blob/main/packages/txwrapper-examples/polkadot/src/polkadot.ts){target=\_blank} includes several reference examples.
416
389
417
390
## Additional Libraries for Submitting a Transaction
418
391
419
-
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.
392
+
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`](https://paritytech.github.io/polkadot-sdk/master/sc_rpc/author/trait.AuthorApiServer.html#tymethod.submit_extrinsic){target=\_blank} or [`author_submitAndWatchExtrinsic`](https://github.com/paritytech/polkadot-sdk/blob/0ae5c5bbd96a600aed81358339be2f16bade4a81/substrate/client/rpc-api/src/author/mod.rs#L69-L78){target=\_blank}, 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