Introduction to Bitcoin Transactions
Bitcoin transactions (often abbreviated as "Tx") are fundamental components of the Bitcoin network. Blocks serve as containers that bundle these transactions together, secured by immense computational power that protects both individual transactions and the entire blockchain.
A transaction can be conceptually understood as a transfer of value. Figure 1 illustrates a simple transaction scenario where Alice sends Bitcoin to Bob. In this transaction:
- The input represents Alice and the amount she's spending
The outputs designate:
- Bob's address and the amount he receives
- Alice's own address (for the change)
The inclusion of Alice in the outputs occurs because transaction inputs and outputs must balance (excluding transaction fees). For instance, if Alice has a 10 BTC input but only wants to send 3 BTC to Bob, the transaction will include:
- 3 BTC to Bob
- 7 BTC back to Alice as change
Transaction Structure Deep Dive
Transaction Inputs (vin)
Each input identifies which UTXO (Unspent Transaction Output) is being spent and provides proof of ownership through an unlocking script. Inputs contain four key elements:
- Transaction ID: References the transaction containing the UTXO
- Output Index (vout): Specifies which UTXO from that transaction
- Unlocking Script (scriptSig): Satisfies the UTXO's spending conditions
- Sequence Number: Used for transaction replacement
Example input structure:
{
"txid": "7957a35fe64f80d234d76d83a2a8f1a0d8149a41d81de548f0a65a8a999f6f18",
"vout": 0,
"scriptSig": "3045022100884d142d...",
"sequence": 4294967295
}Transaction Outputs (vout)
Outputs create new UTXOs and contain:
- Amount in satoshis (smallest Bitcoin unit)
- Locking Script (scriptPubKey): Cryptographic puzzle specifying spending conditions
Example output structure:
{
"value": 0.01500000,
"scriptPubKey": "OP_DUP OP_HASH160 ab68025513c3dbd2f7b92a94e0581f5d50f654e7 OP_EQUALVERIFY OP_CHECKSIG"
}UTXO Model Explained
The UTXO (Unspent Transaction Output) model is Bitcoin's accounting mechanism:
- Each transaction consumes existing UTXOs and creates new ones
- The sum of all UTXOs equals Bitcoin's total circulation
- Your "balance" is the sum of UTXOs associated with your addresses
UTXO Example Scenario
Consider this sequence:
- Zhang mines 12.5 BTC (new UTXO created)
- Zhang spends 2.5 BTC to Li (12.5 BTC UTXO consumed; two new UTXOs created: 2.5 BTC to Li and 10 BTC change back)
- Zhang and Li jointly spend 5 BTC to Wang (combining their 2.5 BTC UTXOs)
👉 Learn more about UTXO mechanics
Transaction Scripts: Locking and Unlocking
Bitcoin uses two types of scripts for transaction validation:
- Locking Script (scriptPubKey): Spending condition placed on output
- Unlocking Script (scriptSig): Solution satisfying the locking script's conditions
Standard P2PKH Script Example
Locking Script (Output):
OP_DUP OP_HASH160 [PublicKeyHash] OP_EQUALVERIFY OP_CHECKSIGUnlocking Script (Input):
[Signature] [PublicKey]The verification process executes both scripts sequentially (Figure 2). If the final stack result is TRUE, the input is valid.
Transaction Fees
Transaction fees:
- Represent the difference between input and output amounts
- Are not explicitly stated in the transaction
- Prioritize transactions for miners (higher fees = faster confirmation)
- Can be adjusted by wallet software
👉 Calculate optimal transaction fees
Advanced Transaction Features
1. Multisignature (Multisig)
Multisig scripts require M signatures from N authorized keys. Example 2/3 multisig locking script:
2 [PubKey1] [PubKey2] [PubKey3] 3 CHECKMULTISIG2. Pay-to-Script-Hash (P2SH)
P2SH allows complex redeem scripts to be represented by their hash:
- Sender locks funds to script hash
- Recipient provides actual script when spending
3. Segregated Witness (SegWit)
SegWit (BIP 141) separates witness data (signatures) from transaction data, providing:
- Elimination of transaction malleability
- Block capacity increase (effective 1.7-2x)
- New address format (Bech32):
bc1q...
SegWit Transaction Example (P2WPKH)
Output Script:
0 [PublicKeyHash]Input Contains:
- Empty scriptSig
- Witness data with signature
Transaction Lifecycle
- Creation: Wallet constructs and signs transaction
- Propagation: Nodes relay transaction via flooding
- Validation: Miners verify transaction against consensus rules
- Confirmation: Inclusion in a mined block
Frequently Asked Questions
Q1: Why does my transaction have multiple inputs/outputs?
A: Wallets combine UTXOs to create sufficient funds (inputs) and generate change outputs to comply with Bitcoin's accounting model.
Q2: How long do transactions typically take?
A: Confirmations depend on network congestion and fee payment. First confirmation averages 10 minutes but can vary.
Q3: What's the difference between legacy and SegWit addresses?
A: SegWit (Bech32) addresses start with "bc1" and offer lower fees, while legacy addresses begin with "1" or "3".
Q4: Can transactions be cancelled?
A: Before confirmation, transactions can sometimes be replaced (with RBF) or double-spent. After confirmation, they're irreversible.
Q5: Why do some wallets estimate fees differently?
A: Fee estimation algorithms analyze recent block inclusion patterns differently. Wallets may use various strategies for optimal fee prediction.
Key Takeaways
- Bitcoin transactions transfer value between parties using inputs and outputs
- The UTXO model provides transparent accounting and privacy features
- Scripting enables advanced functionality like multisig and smart contracts
- SegWit improved scalability, security, and efficiency
- Proper fee estimation ensures timely transaction confirmation
For developers building Bitcoin applications, understanding these transaction mechanics is crucial for creating secure and efficient wallet software and services.