TeachMeBitcoin

P2SH ScriptPubKey Structure

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

P2SH ScriptPubKey Structure

The beauty of P2SH lies in its minimalist locking script. Regardless of how complex the underlying smart contract is, the ScriptPubKey on the blockchain always looks exactly the same.

1. The Locking Script (ScriptPubKey)

A P2SH script follows this three-part template: OP_HASH160 [20-Byte Script Hash] OP_EQUAL

2. Raw Hex Representation

In a raw transaction, a P2SH script is very compact: a9 14 [20-byte-hash] 87

Hex Opcode Purpose
0x49 OP_HASH160 Hash the provided script
0x14 Push 20 Bytes The length of the hash data
0x87 OP_EQUAL Verify the hashes match

3. Comparison to P2PKH

You might notice that OP_HASH160 and a 20-byte hash are also used in P2PKH.

4. The Hidden Logic

Because the script only contains a hash, a miner or observer cannot tell if the output is:

In the next section, we will break down the Redeem Script and how to unlock a P2SH output.

☕ Help support TeachMeBitcoin

TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!