P2WPKH

(pay to witness public key hash)

A Pay-to-Witness-Public-Key-Hash (P2WPKH) script is the standard SegWit script for a direct transfer transaction. The logic for a P2WPKH witness script & output pubKeyScript is exactly the same as a P2PKH input ScriptSig & output pubKeyScript. However, there is a large difference in the op_codes explicitly expressed in the raw transaction. Wallets/clients know that when a P2WPKH output is detected they'll need to insert the common P2PKH op_codes; therefore, a P2WPKH pubKeyScript requires only one specific item: a hashed public key.

OP_Code(s) Review

P2WPKH requires the same three (3) pieces of data & four (4) op_codes as P2PKH. However, as we see in the first step below, the initial formatting for the ScriptPubKey is different.

# WitnessScript

[witness]

[public-key]

[signature]

# PubKeyScript

<dup>

<hash160>

[hash160 [public-key]]

<equalverify>

<checksig>

Step 1

Deserialize the witness to get the signature & public key