6.1 Introduction
Bitcoin transactions are the most critical part of the Bitcoin system. According to Bitcoin's design principles, every other component exists to ensure transactions can be created, propagated, validated, and ultimately added to the global ledger (blockchain). At their core, Bitcoin transactions are data structures that encode value transfers between participants.
In this chapter, we will examine:
- The various forms of Bitcoin transactions
- The information they contain
- How they are created and validated
- How they become part of the permanent transaction record
When we use the term "wallet" in this chapter, we refer to transaction-building software, not just a database of keys.
6.2 Transaction Details
6.2.1 Transaction - Behind the Scenes
What you see in block explorers is a simplified representation. The actual transaction structure differs significantly from what user interfaces display.
Example decoded transaction:
{
"version": 1,
"locktime": 0,
"vin": [
{
"txid": "7957a35fe64f80d234d76d83a2a8f1a0d8149a41d81de548f0a65a8a999f6f18",
"vout": 0,
"scriptSig": "3045022100884d142d...",
"sequence": 4294967295
}
],
"vout": [
{
"value": 0.01500000,
"scriptPubKey": "OP_DUP OP_HASH160 ab680255... OP_EQUALVERIFY OP_CHECKSIG"
},
{
"value": 0.08450000,
"scriptPubKey": "OP_DUP OP_HASH160 7f9b1a7f... OP_EQUALVERIFY OP_CHECKSIG"
}
]
}Key observations:
- No explicit sender/receiver addresses
- Values are in satoshis
- Cryptographic puzzles (locking scripts) define spending conditions
- Complex fields not visible in simplified views
6.3 Transaction Inputs and Outputs
6.3.1 Transaction Outputs (UTXOs)
Fundamental building blocks with two components:
- Amount in satoshis
- Cryptographic puzzle (locking script)
Example output:
{
"value": 0.10000000,
"scriptPubKey": "OP_DUP OP_HASH160 7f9b1a7fb68d60c536c2fd8aeaa53a8f3cc025a8 OP_EQUALVERIFY OP_CHECKSIG"
}6.3.2 Transaction Inputs
Inputs reference UTXOs being spent and provide unlocking proofs:
- Reference to previous transaction (txid)
- Output index (vout)
- Unlocking script (scriptSig)
- Sequence number
Example input:
{
"txid": "7957a35fe64f80d234d76d83a2a8f1a0d8149a41d81de548f0a65a8a999f6f18",
"vout": 0,
"scriptSig": "3045022100884d142d...",
"sequence": 4294967295
}6.3.3 Transaction Fees
Calculated as:
Fee = Sum(Inputs) - Sum(Outputs)
Best practices:
- Fees are based on transaction size (bytes), not value
- Dynamic fee estimation is essential
- Services like bitcoinfees.21.co provide recommended rates
👉 Calculate your exact fee requirements
6.4 Bitcoin Scripts
6.4.1 P2PKH (Pay-to-Public-Key-Hash)
Standard transaction type with:
- Locking script:
OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG - Unlocking script:
<signature> <publicKey>
Validation combines both scripts:
<signature> <publicKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG6.5 Digital Signatures (ECDSA)
6.5.1 Signature Creation
- Uses ephemeral key pair (k, R)
- Produces signature values (R, S)
- Must never reuse k values
6.5.2 Signature Verification
- Uses R, S, public key, and message
- Valid if calculated point matches R
6.5.3 SIGHASH Types
| Flag | Description |
|---|---|
| ALL | Signs all inputs/outputs |
| NONE | Signs inputs only |
| SINGLE | Signs corresponding input/output |
| ANYONECANPAY | Modifier for flexibility |
6.6 Addresses and Balances
Key points:
- Addresses are derived from public key hashes
Balances are calculated by wallets by:
- Summing all received UTXOs
- Subtracting spent outputs
- Tracking unspent outputs (UTXO set)
- These are abstractions - not native blockchain concepts
FAQ
Q: Where are Bitcoin addresses stored in transactions?
A: They aren't directly stored. Addresses are derived from the public key hashes in locking scripts.
Q: How do wallets calculate balances?
A: By scanning the blockchain and summing values from UTXOs that belong to the wallet's addresses.
Q: Why doesn't the transaction show my exact balance?
A: The blockchain only records individual transactions. Balance displays are wallet-side calculations.
Q: What happens if transaction fees are too low?
A: Low-fee transactions may experience delayed confirmations or require fee bumping.