Bitcoin Transactions
Quick refs: sighash.md, serialization.md, malleability.md, rbf-cpfp.md, v3-truc.md
Anatomy
version (4 bytes)
[marker (0x00) flag (0x01)] ← only if SegWit, signals witness presence
vin count (varint)
vin[]:
prevout: { txid (32), vout (4) }
scriptSig (varint-prefixed) ← legacy unlocking script
sequence (4 bytes)
vout count (varint)
vout[]:
value (8 bytes, sats)
scriptPubKey (varint-prefixed)
[witness[]] ← if marker/flag present, one stack per input
locktime (4 bytes)
Version: 1, 2 (BIP68 relative locktimes require v≥2), 3 (TRUC, BIP431).
txid vs wtxid
txid = SHA256d(tx without witness data) — what spends and merkle root
reference.
wtxid = SHA256d(tx with witness) — what coinbase witness commitment
uses (BIP141 witness merkle root).
- For legacy non-segwit txs,
txid == wtxid.
Inputs & outputs
- Input spends a previous output (
txid:vout) and proves authorization
via scriptSig + (for SegWit) witness stack. Value = whatever the
prevout had — never serialized in the spending tx (must be looked up).
- Output locks N sats to a
scriptPubKey. Address formats:
- P2PKH (
1...) — OP_DUP OP_HASH160 <20> OP_EQUALVERIFY OP_CHECKSIG
- P2SH (
3...) — OP_HASH160 <20> OP_EQUAL
- P2WPKH (
bc1q...) — OP_0 <20> (Bech32)
- P2WSH (
bc1q...) — OP_0 <32> (Bech32)
- P2TR (
bc1p...) — OP_1 <32> (Bech32m)
Sighash flags
See sighash.md for full combinatorics. Summary:
| Flag |
Signs |
ALL (0x01) |
All inputs, all outputs |
NONE (0x02) |
All inputs, no outputs (anyone can change outputs) |
SINGLE (0x03) |
All inputs, only output at same index |
| ANYONECANPAY (0x80) |
Only this input's prevout (others can be added) |
Taproot adds SIGHASH_DEFAULT (0x00 = ALL with new digest) and changes
serialization (BIP341).
TRUC v3 (BIP431)
- Version=3 marks the tx as TRUC.
- Constraints:
vsize ≤ 10000 vB, ≤1 unconfirmed ancestor, ≤1 unconfirmed
descendant, ancestor must also be v3.
- Sibling eviction: a v3 child can replace a sibling without paying for
the sibling's bandwidth.
- Designed for Lightning anchor / commitment fee bumping: enables 0-fee
parent + child paying full package fee.
Ephemeral anchors
- Anchor with
value=0 and trivially-spendable script (e.g., OP_TRUE).
- Must be spent in the same package as its parent (mempool rule).
- Combined with TRUC v3, replaces existing anchor outputs (BOLT-3) with
no-cost variant.
See also
1---2name: bitcoin-transactions3description: |4 Bitcoin transaction structure: inputs, outputs, witness, version, locktime,5 serialization (legacy + segwit + wtxid), sighash modes, malleability,6 TRUC v3, ephemeral anchors. Quick-ref docs cover sighash combinatorics,7 serialization wire format, malleability classes, RBF/CPFP rules.8 USE WHEN: building/decoding transactions, choosing sighash flags,9 understanding txid vs wtxid, fee bumping logic.10allowed-tools: Read, Grep, Glob11metadata:12 source: https://skillmd.com/skills/claude-dev-suite/bitcoin-transactions13---1415# Bitcoin Transactions1617> **Quick refs**: [sighash.md](quick-ref/sighash.md), [serialization.md](quick-ref/serialization.md), [malleability.md](quick-ref/malleability.md), [rbf-cpfp.md](quick-ref/rbf-cpfp.md), [v3-truc.md](quick-ref/v3-truc.md)1819## Anatomy2021```22version (4 bytes)23[marker (0x00) flag (0x01)] ← only if SegWit, signals witness presence24vin count (varint)25vin[]:26 prevout: { txid (32), vout (4) }27 scriptSig (varint-prefixed) ← legacy unlocking script28 sequence (4 bytes)29vout count (varint)30vout[]:31 value (8 bytes, sats)32 scriptPubKey (varint-prefixed)33[witness[]] ← if marker/flag present, one stack per input34locktime (4 bytes)35```3637**Version**: 1, 2 (BIP68 relative locktimes require v≥2), 3 (TRUC, BIP431).3839## txid vs wtxid4041- `txid = SHA256d(tx without witness data)` — what spends and merkle root42 reference.43- `wtxid = SHA256d(tx with witness)` — what coinbase witness commitment44 uses (BIP141 witness merkle root).45- For legacy non-segwit txs, `txid == wtxid`.4647## Inputs & outputs4849- **Input** spends a previous output (`txid:vout`) and proves authorization50 via scriptSig + (for SegWit) witness stack. Value = whatever the51 prevout had — never serialized in the spending tx (must be looked up).52- **Output** locks N sats to a `scriptPubKey`. Address formats:53 - P2PKH (`1...`) — `OP_DUP OP_HASH160 <20> OP_EQUALVERIFY OP_CHECKSIG`54 - P2SH (`3...`) — `OP_HASH160 <20> OP_EQUAL`55 - P2WPKH (`bc1q...`) — `OP_0 <20>` (Bech32)56 - P2WSH (`bc1q...`) — `OP_0 <32>` (Bech32)57 - P2TR (`bc1p...`) — `OP_1 <32>` (Bech32m)5859## Sighash flags6061See [sighash.md](quick-ref/sighash.md) for full combinatorics. Summary:6263| Flag | Signs |64|------|-------|65| `ALL` (0x01) | All inputs, all outputs |66| `NONE` (0x02) | All inputs, no outputs (anyone can change outputs) |67| `SINGLE` (0x03) | All inputs, only output at same index |68| `\| ANYONECANPAY` (0x80) | Only this input's prevout (others can be added) |6970Taproot adds `SIGHASH_DEFAULT` (0x00 = ALL with new digest) and changes71serialization (BIP341).7273## TRUC v3 (BIP431)7475- Version=3 marks the tx as TRUC.76- Constraints: `vsize ≤ 10000 vB`, ≤1 unconfirmed ancestor, ≤1 unconfirmed77 descendant, ancestor must also be v3.78- Sibling eviction: a v3 child can replace a sibling without paying for79 the sibling's bandwidth.80- Designed for Lightning anchor / commitment fee bumping: enables 0-fee81 parent + child paying full package fee.8283## Ephemeral anchors8485- Anchor with `value=0` and trivially-spendable script (e.g., `OP_TRUE`).86- Must be spent in the same package as its parent (mempool rule).87- Combined with TRUC v3, replaces existing anchor outputs (BOLT-3) with88 no-cost variant.8990## See also9192- [scripts/SKILL.md](../scripts/SKILL.md) — opcodes, output type construction93- [taproot/SKILL.md](../taproot/SKILL.md) — Taproot witness, SIGHASH_DEFAULT94- [psbt/SKILL.md](../psbt/SKILL.md) — partially-signed tx workflow