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:
createrawtransaction— Build an unsigned transaction specifying inputs and outputsdecoderawtransaction— Inspect a hex-encoded transaction in human-readable JSONsignrawtransactionwithwallet— Sign the transaction with wallet keyssendrawtransaction— 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.