Skip to main content

Raw Transaction | Bitcoin Glossary | Mapping Bitcoin

Raw Transaction

Development

Also known as: raw tx, serialized transaction

A Bitcoin transaction in its serialized hexadecimal format, containing all the data needed for validation and broadcast. Raw transactions can be constructed, inspected, and signed offline before being broadcast to the network.

Overview

A raw transaction is the byte-level representation of a Bitcoin transaction, typically displayed as a hexadecimal string. It contains all the information a node needs to validate and relay the transaction: the version, inputs (referencing previous outputs being spent), outputs (defining new locking conditions), witness data (for SegWit transactions), and the locktime. Working with raw transactions gives developers complete control over transaction construction.

Raw Transaction Structure

Serialized Transaction Layout:

┌──────────┬───────────┬───────────┬──────────┬──────────┐
│ Version  │  Input    │  Output   │ Witness  │ Locktime │
│ (4 bytes)│  Count +  │  Count +  │ (SegWit  │ (4 bytes)│
│          │  Inputs   │  Outputs  │  only)   │          │
└──────────┴───────────┴───────────┴──────────┴──────────┘

Each Input:                    Each Output:
┌─────────────────────┐        ┌──────────────────────┐
│ Previous TX ID      │        │ Value (satoshis)     │
│ (32 bytes)          │        │ (8 bytes)            │
├─────────────────────┤        ├──────────────────────┤
│ Output Index        │        │ Script Length         │
│ (4 bytes)           │        │ (varint)             │
├─────────────────────┤        ├──────────────────────┤
│ ScriptSig Length    │        │ ScriptPubKey         │
│ + ScriptSig        │        │ (locking script)     │
├─────────────────────┤        └──────────────────────┘
│ Sequence            │
│ (4 bytes)           │
└─────────────────────┘

Working with Raw Transactions via RPC

Bitcoin Core's RPC interface provides commands for each stage of raw transaction handling:

  1. createrawtransaction — Build an unsigned transaction specifying inputs and outputs
  2. decoderawtransaction — Inspect a hex-encoded transaction in human-readable JSON
  3. signrawtransactionwithwallet — Sign the transaction with wallet keys
  4. sendrawtransaction — Broadcast the signed transaction to the network

Use Cases

  • Offline signing — Construct transactions on an online machine, sign on an air-gapped device, and broadcast from the online machine
  • Custom scripts — Build transactions with non-standard locking scripts for testing or advanced protocols
  • Fee control — Manually set inputs and outputs for precise fee management
  • Transaction analysis — Decode and inspect existing transactions for debugging or forensic purposes

PSBT as an Alternative

For most multi-step signing workflows, PSBTs (BIP174) are now preferred over raw transactions. PSBTs carry additional metadata (UTXO information, derivation paths, partial signatures) that raw hex transactions lack, making them safer and more portable for hardware wallet and multisig workflows.

Common Misconception

A raw transaction is not "raw" in the sense of being incomplete or unprocessed. A fully signed raw transaction is a valid, complete Bitcoin transaction ready for broadcast. The term "raw" simply refers to the serialized binary format as opposed to a human-readable JSON representation.