P2WPKH – Pay-to-Witness-Public-Key-Hash

This hex representation corresponds to the locking script (scriptPubKey) in a Pay-to-Witness-Public-Key-Hash (P2WPKH) output. When a Bitcoin transaction creates an output with this script, it essentially “locks” the funds to the specified conditions.

Let’s dissect an example, the following is a hexadecimal representation of a P2WPKH script:

| OP_0 | Push 20 Bytes | Public Key Hash                            | Witness Version | OP_CHECKSIG |
| 00   | 14            | 7b2583b7551e0e5e90638e7a45dced650ee36082   | 01              | 21          |

Breaking it down:

  1. 00: OP_0
  2. 14: Push 20 bytes
  3. 7b2583b7551e0e5e90638e7a45dced650ee36082: 20-byte Public Key Hash
  4. 01: Witness version
  5. 21: OP_CHECKSIG

Now, let’s explain each part:

  • OP_0 (00): This opcode represents the number 0 in Bitcoin’s scripting language. In this context, it’s a placeholder for the witness data.
  • Push 20 bytes (14): This opcode indicates that the next 20 bytes are data to be pushed onto the stack. The 20 bytes represent the RIPEMD-160 hash of the SHA-256 hash of the public key. This is the public key hash (PKH).
  • Public Key Hash (20 bytes): The actual public key hash in this example is 7b2583b7551e0e5e90638e7a45dced650ee36082. This hash is derived from the public key using a series of cryptographic hash functions.
  • Witness Version (01): This byte represents the witness version. In P2WPKH scripts, it’s typically 0x01, indicating SegWit version 1.
  • OP_CHECKSIG (21): This opcode is used to check the signature against the public key. It verifies that the signature is valid for the provided public key.

So, the entire script represents a Pay-to-Witness-Public-Key-Hash output, where the spending conditions are governed by providing a valid witness (containing signature and public key) that satisfies the associated public key hash.

So, to sum up, this P2WPKH script is used to define the conditions under which the funds can be spent (unlocked). The actual unlocking occurs when a transaction input provides the necessary witness data to satisfy the conditions specified in the locking script.