Pay-to-Script-Hash (P2SH)

Pay-to-Script-Hash (P2SH) is a Bitcoin feature that allows transactions to be sent to a hash representing a script, rather than to a specific public key or address. With P2SH, the actual spending conditions are hidden until the bitcoin is spent. When someone creates a P2SH transaction, they include the hash of a redeem script, which defines the rules for spending the funds—like requiring signatures from multiple people or setting more complex requirements.

For example, if Alice wants to send Bob some bitcoin using P2SH, she doesn't need to know the exact script Bob wants to use. Instead, Bob gives Alice the hash of his chosen script, and Alice locks the coins to that hash. Later, when Bob spends his bitcoin, he provides the complete redeem script (matching the hash) and fulfills its conditions—such as supplying the necessary signatures.

P2SH adds flexibility to Bitcoin by supporting various custom scripts and more advanced features, including compatibility with updates like SegWit. It also enhances privacy for recipients since only the hash of the script is revealed when receiving funds; the full details stay hidden until the coins are used.