LogoLogo
  • Introduction
  • BSV Blockchain
    • Blocks
    • Transactions
    • Proof of Work
    • Capabilities
    • Economic Model of Governance
    • Digital Asset Recovery
  • Network Policies
    • High-Level Architecture
    • Mining
    • Standard and Local Policies
    • Consensus Rules
    • Local Policies
  • Node Operations
    • Node Software
    • Bitcoin Server Network (BSN)
    • ChainTracker
    • Transaction Validation
    • UTXO Storage
    • Mempool
    • Block Assembler
    • Block Validation
    • Mining Software
    • Pruning transactions
    • Responsibilities of a Node
  • Light Clients and SPV Processes
    • Simplified Payment Verification (SPV)
      • Proof of Publication in a block
      • Instant Payments
      • Proof of Integrity
    • Light Clients in Blockchain
  • Transaction Lifecycle
    • Transaction Inputs and Outputs
    • Script
    • Transaction Flow
    • Constructing a transaction
    • Sequence Number and Time Locking
    • Transaction Templates
    • Transaction Processing
    • Opcodes used in Script
  • Privacy
    • Keys and Identity
    • Private vs Anonymous
    • Digital Signatures
    • Privacy in Public Blockchain
Powered by GitBook
On this page
  1. Transaction Lifecycle

Constructing a transaction

Understanding transaction bitwise

PreviousTransaction FlowNextSequence Number and Time Locking

Last updated 1 year ago

We have already looked at the composition of a transaction. Now, let's dig a bit deeper. The following table shows the data structure of a transaction.

Field
Description
Size

Version no

currently 2

4 bytes

In-counter

1 - 9 bytes

list of inputs

<in-counter> qty with variable length per input

Out-counter

1 - 9 bytes

list of outputs

<out-counter> qty with variable length per output

if non-zero and sequence numbers are < 0xFFFFFFFF: block height or timestamp when transaction is final

4 bytes

The following image provides an example of a typical raw transaction (P2PKH transaction with two inputs and two outputs):

The colours help to differentiate every field present in the transaction. Input script is denoted as scriptSig, and output script is denoted as scriptPubKey (due to the nature of the input script being a signature and output being a script locking the funds to a public key).

As shown in the attachment below, each field in the transaction is modularised i.e. you can build a raw transaction one by one by adding each of these fields in the right format and endianness. These transactions are usually built using well-defined libraries and functions available in various programming languages.

There will often be visualisation tools which will present the transaction details in a much more readable format; for example, below is the translated version of the input and output scripts for the raw transactions in discussion.

Once the transaction is constructed, it is submitted to a mining node. This can be done using the RPC endpoint (called bitcoind), which is made available by the mining nodes to users. Some mining nodes also use a service component built on top of bitcoind called Merchant API or mAPI. mAPI provides a REST interface for broadcasting a transaction and returns the Merkle Proof of the transaction once the block is mined. Either way, the broadcasting of transaction is a responsibility of the user who uses either of the methods mentioned above.

positive integer VI =

positive integer VI =

VarInt
Input Structure
VarInt
Output Structure
nLocktime
12KB
txbits.xlsx