P2PKH vs P2SH

So as a recap, in Bitcoin, senders specify a locking script in the output of the transaction they are sending, and recipients provide an unlocking script in the input whenever they want to redeem their bitcoin.

In the previous section, we gave the example of Pay to Pub Key Hash, or P2PKH.

In this scheme, the vendor, or the recipient of the transaction, says: “Send your coins to the hash of this Public Key.” And later, the vendor has to provide a public key and a signature, in order to redeem these bitcoins.

This is by far the simplest and most common case.

On the other hand, there is the more flexible Pay to Script Hash.

Rather than paying to just a public key hash, we can now pay to a more complicated set of instructions.

In this scheme, the vendor says: “Send your coins to the hash of this Script.

I’ll provide the script and the data to make the script evaluate to true when I redeem the coins.” This makes sense because we don’t really want vendors to require customers to create a complicated output script first.

It’s much more customer friendly if the recipient of the transaction, the vendor, specifies the script.

How P2SH Works