P2PKH and P2SH
Terms used in this lesson
- P2PKH
- Pay to Public Key Hash, a legacy Bitcoin output template that commits to the hash of a public key.
- P2SH
- Pay to Script Hash, a legacy Bitcoin output template that commits to a redeem script.
- Hash160
- SHA-256 followed by RIPEMD-160, producing the 20-byte hash used by several Bitcoin spending conditions.
- Witness
- Signatures, scripts, or other data supplied to satisfy a Bitcoin output’s spending condition.
- CHECKSIG
- The Bitcoin Script operation that checks whether a signature is valid for the required public key and transaction message.
- OP_DUP
- A Bitcoin Script operation that copies the top stack item.
- OP_HASH160
- A Bitcoin Script operation that replaces the top stack item with its Hash160 digest.
- OP_EQUALVERIFY
- A Bitcoin Script operation that compares two values and immediately fails if they differ.
Legacy templates separate address-friendly commitments from revealed spending scripts.
Loading lesson visuals...
Learn the idea
P2PKH means Pay to Public Key Hash. Its output commits to HASH160 of a public key and a spend reveals the public key plus signature. P2SH means Pay to Script Hash. Its output commits to HASH160 of a redeem script and a spend reveals that script plus data that satisfies it. Both are legacy templates whose scriptSig participates in the transaction's non-witness serialization.
Create a P2PKH commitment
The output script duplicates and hashes the supplied public key, compares it with a committed 20-byte key hash, then checks a signature.
Inspect every idea above to open it.
Consensus verifies the script's bytecode behavior. Labels such as escrow or recovery are interpretations used by wallets and people.
The questions unlock after every required learning activity
Inspect every guided idea, open the worked example, rebuild its mechanism, and complete the deterministic lesson tool. Your progress is saved automatically.