Transaction Structure
Overview
P2PKH transactions consist of inputs and outputs, each containing scripts that define how funds are locked and unlocked.
Output (Locking Script - ScriptPubKey)
When sending funds to a P2PKH address, the transaction output contains a ScriptPubKey that locks the funds. This script specifies the conditions required to spend the funds.
OP_DUP
OP_HASH160
OP_PUSHBYTES_20
24bc22345d16821eb478da2408245b831ca90431
OP_EQUALVERIFY
OP_CHECKSIG
# Hex value: 76a91424bc22345d16821eb478da2408245b831ca9043188acThe ScriptPubKey contains the hash of the recipient's public key, not the public key itself. Funds remain locked until someone provides the correct public key and a valid signature.
Input (Unlocking Script - ScriptSig)
To spend funds from a P2PKH address, the transaction input must provide a ScriptSig containing the data needed to satisfy the locking conditions.
OP_PUSHBYTES_72
3044022041b2a8a8e6c0c8e5b1c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8091a2b3c4d5e6f022012a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f708101
OP_PUSHBYTES_33
0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798
# Hex value: 483044022041b2a8a8e6c0c8e5b1c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8091a2b3c4d5e6f022012a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f708101210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798Script Execution
When a transaction is validated, the ScriptSig and ScriptPubKey are concatenated and executed together:
- The signature and public key are pushed onto the stack from the ScriptSig.
- OP_DUP duplicates the public key on the stack.
- OP_HASH160 hashes the duplicated public key (SHA-256 followed by RIPEMD-160).
- The expected public key hash is pushed from the ScriptPubKey.
- OP_EQUALVERIFY verifies that the computed hash matches the expected hash.
- OP_CHECKSIG verifies the signature against the public key and transaction data. Push 1 on the stack if it is valid.
If all operations succeed, the transaction is valid and the funds are unlocked for spending.