Transaction Construction and Signing
This page will discuss the transaction format in Betelgeuse and how to create, sign, and broadcast transactions. Like the other pages in this guide, this page demonstrates some of the available tools. Always refer to each tool's documentation when integrating.
Transaction Construction
Betelgeuse provides some basic information common to all transactions.
Address: The SS58-encoded address of the sending account.
Block Hash: The hash of the checkpoint block.
Block Number: The number of the checkpoint block.
Genesis Hash: The genesis hash of the chain.
Metadata: The SCALE-encoded metadata for the runtime when submitted.
Nonce: The nonce for this transaction.*
Spec Version: The current spec version for the runtime.
Transaction Version: The current version for transaction format.
Tip: Optional, the tip to increase transaction priority.
Era Period: Optional, the number of blocks after the checkpoint for which a transaction is valid. If zero, the transaction is immortal.
*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 simultaneously.
Each transaction will have its own (or no) parameters to add. For example, thetransferKeepAlive
function from the Balances pallet will take:
dest
: Destination address#[compact] value
: Number of tokens (compact encoding)
Once you have all the necessary information, you will need to:
Construct an unsigned transaction.
Create a signing payload.
Sign the payload.
Serialize the signed payload into a transaction.
Submit the serialized transaction.
Parity provides the following tools to help perform these steps:
Betelgeuse-JS Tools
Betelgeuse Web wallet contains a set of command line tools for interacting with a Substrate client, including "Signer CLI" to create, sign, and broadcast transactions.
This example will use thesigner submit
command, which will create and submit the transaction. ThesignersendOffline
command has the same API but will not broadcast the transaction. submit
andsendOffline
must be connected to a node to fetch the current metadata and construct a valid transaction. Their API has the format:
Signing:
For example, let's send 0.5 ETP3 from121X5bEgTZcGQx5NZjwuTjqqKoiG8B2wEAvrUFjuw24ZGZf2
to 15vrtLsCQFG3qRYUcaEeeEih4JwepocNJHkpsrqojqnZPc2y
.
This will return a payload to sign and an input waiting for a signature. Take this payload and use your normal signing environment (e.g., air-gapped machine, VM, etc.). Sign the payload:
Save the output and bring it to the machine that you will broadcast from, enter it into the submit
's signature field, and send the transaction (or return the serialized transaction if using sendOffline
).
TX Wrapper
Parity provides an SDK called TxWrapper to generate and sign transactions offline if you do not want to use the CLI for signing operations.
Import private key
Derive an address from a public key
Construct a transaction offline
Construct a signing payload
Serialize a signed transaction
Decode payload types
You may want to decode payloads to verify their contents prior to submission.
Check a transaction's hash
Transaction Signing
There are several ways to submit a signed payload:
Signer CLI (
yarn run:signer submit --tx <signed-transaction> --ws <endpoint>
)Substrate API Sidecar
RPC with
author_submitExtrinsic
orauthor_submitAndWatchExtrinsic
, the latter of which will subscribe you to events to be notified as a transaction gets validated and included in the chain.
Last updated