Advanced Transactions and Scripting

This chapter covers advanced transactions and scripting. Here, we will learn about different transaction types and the scripts that create them. You'll use concepts like pay-to-script-hash and multi-sig in almost any Bitcoin development project.

Benefits of P2SH

The P2SH feature offers the following benefits compared to the direct use of complex scripts in locking outputs:

  • Complex scripts are replaced by shorter fingerprints in the transaction output, making the transaction smaller.
  • Scripts can be coded as an address, so the sender and the sender's wallet don't need complex engineering to implement P2SH.
  • P2SH shifts the burden of constructing the script to the recipient, not the sender.
  • P2SH shifts the burden in data storage for the long script from the output (which additionally to being stored on the blockchain is in the UTXO set) to the input (only stored on the blockchain).
  • P2SH shifts the burden in data storage for the long script from the present time (payment) to a future time (when it is spent).
  • P2SH shifts the higher transaction fee costs of a long script from the sender to the recipient, who has to include the long redeem script to spend it.