BitcoinMachine
TRANSACTIONS / SERIALIZATION
Transaction Serialization
A Bitcoin transaction is a precisely-encoded binary structure. Every node on the network parses the same bytes identically. Legacy transactions have four top-level sections: version · inputs · outputs · locktime. SegWit transactions (BIP141) insert a 0x00 0x01 marker+flag after the version and append per-input witness stacks before locktime — without changing how the txid is computed.
LEGACY FORMAT
SEGWIT FORMAT (BIP141)
FIELDBYTESENCODINGNOTES
version4LE uint321 = original; 2 = BIP68 relative locktime
in_countvarint1–9 B# inputs (≤0xFC → 1 byte; 0xfd → 3 bytes…)
prev txid32LE bytesprevious tx hash stored byte-reversed
prev vout4LE uint32output index; 0xffffffff = coinbase
scriptSig_lenvarint0x00 for SegWit inputs
scriptSigvariablerawDER sig + pubkey for P2PKH
sequence4LE uint320xffffffff=final; 0xfffffffe=RBF-opt-in
out_countvarint# outputs
value8LE int64satoshis (100,000,000 sat = 1 BTC)
scriptPubKeyvariablerawscript/">locking script (len varint + bytes)
locktime4LE uint320=none; <500M=block-height/">block height; ≥500M=unix ts
PARSE RAW TRANSACTIONclick any coloured field to inspect
VARINT ENCODER / DECODER
VALUE RANGESTORAGE (bytes)PREFIXEXAMPLE
0–2521fc = 252
253–6553530xfdfd 0100 = 256
65536–429496729550xfefe 00000100 = 65536
4294967296–2⁶⁴−190xffff 0000000001000000 = 4G