Skip to content

Commit e79482d

Browse files
committed
add Polkadot Rust Docs references; formatting
1 parent 170f902 commit e79482d

File tree

2 files changed

+66
-120
lines changed

2 files changed

+66
-120
lines changed

develop/toolkit/integrations/transaction-construction.md

Lines changed: 33 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -17,55 +17,38 @@ For further reading, refer to [blocks, transactions, and fees](/polkadot-protoco
1717

1818
Polkadot has some basic transaction information that is common to all transactions.
1919

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.
3432

3533
!!!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.
3835

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.
4137

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:
4439

4540
- `dest`: Destination address
4641
- `#[compact] value`: Number of tokens (compact encoding)
4742

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.
5044

5145
**Mode and MetadataHash**
5246

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`.
6048

6149
**Serialized transactions and metadata**
6250

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}.
6952

7053
**Transaction Flow**
7154

@@ -81,23 +64,18 @@ Parity provides several tools to help perform these steps.
8164

8265
## Polkadot-JS Tools
8366

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.
8768

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.
9270

93-
Start by installing the Signer CLI:
71+
Start by installing the Signer CLI.
9472

9573
```bash
9674
npm install -g @polkadot/signer-cli
9775
```
9876

9977
To create a transaction, you need to connect to a chain, enabling the creation of a transaction using the chain's metadata.
100-
Here is the format for `submit` or `sendOffline`:
78+
Here is the format for `submit` or `sendOffline`.
10179

10280
```bash
10381
polkadot-js-signer <submit|sendOffline> --account <from-account-ss58> --ws <endpoint> <module.method> [param1] [...] [paramX]
@@ -138,26 +116,26 @@ Let's say you want to send 1 WND from `5F4c8mNz6schf2WMXQZiz1eyR1GGxrMf2coXpAn8m
138116
First fund the sending account. You can use the [Westend Faucet](https://faucet.polkadot.io/westend) for that.
139117
Request some tokens for `5F4c8mNz6schf2WMXQZiz1eyR1GGxrMf2coXpAn8mNjxyzp2`.
140118

141-
Next call submit to create the transaction and which will give you the payload to sign:
119+
Next call submit to create the transaction and which will give you the payload to sign.
142120

143121
```bash
144122
polkadot-js-signer submit --account 5F4c8mNz6schf2WMXQZiz1eyR1GGxrMf2coXpAn8mNjxyzp2 --ws wss://asset-hub-westend-rpc.n.dwellir.com balances.transferKeepAlive 5FnudgwK8xJvmujsXXP35pF2xwskhHQzBSRM8KZhXjnEz5gD 1000000000000
145123
```
146124

147-
This will return a payload to sign and an input waiting for a signature. Something like this:
125+
This will return a payload to sign and an input waiting for a signature.
148126

149127
```
150128
Payload: 0x040300ff4a83f1...a8239139ff3ff7c3f6
151129
Signature>
152130
```
153131

154-
Take this payload and use your normal signing environment (e.g. air gapped machine, VM, etc.). In a separate tab in your terminal, sign the payload:
132+
Take this payload and use your normal signing environment (e.g. air gapped machine, VM, etc.). In a separate tab in your terminal, sign the payload.
155133

156134
```bash
157135
polkadot-js-signer sign --account 5F4c8mNz6schf2WMXQZiz1eyR1GGxrMf2coXpAn8mNjxyzp2 --seed "south ladder exile ... grape rival settle coil" --type sr25519 0x040300ff4a83f1...a8239139ff3ff7c3f6
158136
```
159137

160-
This will output the signature of the transaction:
138+
This will output the signature of the transaction.
161139
```
162140
Signature: 0xe6facf194a8e...413ce3155c2d1240b
163141
```
@@ -350,14 +328,9 @@ You will get useful output in the terminal with details like the events that wer
350328
polkadot-js-signer submit --tx <signedTransaction> --ws <endpoint>
351329
```
352330

353-
## TxWrapper
331+
## Txwrapper
354332

355-
If you do not want to use the CLI for signing operations, Parity provides an SDK called
356-
[TxWrapper Core](https://github.com/paritytech/txwrapper-core){target=\_blank} to generate and sign transactions
357-
offline. For Polkadot, Kusama, and select parachains, use the `txwrapper-polkadot` package. Other
358-
Substrate-based chains will have their own `txwrapper-{chain}` implementations. See the
359-
[examples](https://github.com/paritytech/txwrapper-core/blob/main/packages/txwrapper-examples/README.md){target=\_blank}
360-
for a guide.
333+
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.
361334

362335
### Creating a Transaction, Signing, and Submitting
363336

@@ -369,9 +342,9 @@ npx @acala-network/chopsticks --config=polkadot -p 9944
369342
```
370343
You should get a Polkadot network running on port 9944.
371344

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.
373346

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}:
375348

376349
```
377350
git clone https://github.com/paritytech/txwrapper-core
@@ -380,7 +353,7 @@ yarn install && yarn build
380353
cd packages/txwrapper-examples
381354
```
382355

383-
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}:
384357
```
385358
yarn run build
386359
yarn run polkadot
@@ -412,8 +385,8 @@ Decoded Transaction
412385
Amount: "10000000000"
413386
```
414387

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.
416389

417390
## Additional Libraries for Submitting a Transaction
418391

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

Comments
 (0)