P2PKH: BSV's Most Common Payment Script Template Explained

P2PKH (Pay to Public Key Hash) is the most basic payment script in Bitcoin/BSV. This article breaks down its core logic, workflow, relationship with addresses, unlocking conditions, and why BSV developers need to understand it.

Ethan Lin

Ethan Lin

technical_editor

Published Jun 1, 20264 min read

In a Nutshell

P2PKH stands for "Pay to Public Key Hash." It is one of the most common payment script templates in Bitcoin/BSV.

The core logic is: an output locks funds to a public key hash, and to spend it, the spender must provide a matching public key and a valid digital signature.

What Problem Does P2PKH Solve?

Ordinary payments need to answer two questions:

  • When receiving: How to specify who can spend the money in the future?
  • When spending: How to prove you are the authorized person?

P2PKH's answer:

  • When receiving, the locking script records the public key hash.
  • When spending, the unlocking script provides the public key and signature.
  • Nodes check if the public key hash matches and verify the signature.

This way, the receiver does not need to expose the full public key during receipt; only the address is required.

Breaking Down the Name

P2PKH can be broken down as:

  • Pay To Public Key Hash
  • Payment → To → Public Key Hash

Note: It is not a direct payment to a public key, but to the hash of a public key.

The typical flow is:

Private key → Public key → Public key hash → Address → P2PKH locking script

The address is what users see as a payment identifier, while the locking script is the real on-chain locking condition.

Intuition Behind the P2PKH Locking Script

The P2PKH locking script roughly expresses:

  1. Give me a public key.
  2. I check if the hash of this public key equals the locked hash.
  3. Give me a signature.
  4. I verify the signature using this public key.
  5. Only if all pass, allow spending.

This is the real logic behind ordinary address payments.

Intuition Behind the P2PKH Unlocking Script

When spending a P2PKH output, the input typically provides:

  • Signature
  • Public key

These two pieces of data are placed on the script execution stack and run together with the locking script. If the public key hash matches and the signature verifies, the script result is true.

Why Not Lock to the Public Key Directly?

Early Bitcoin also had Pay to Public Key (direct pay to public key). P2PKH chooses to lock to the public key hash for several benefits:

  • Shorter addresses, more user-friendly.
  • Does not expose the full public key during receipt, improving privacy.
  • The public key is only revealed when spending.
  • Addresses can include a checksum, reducing the risk of manual input errors.

For beginners, remember: An address usually represents a public key hash, not the public key encoded directly.

P2PKH and UTXO

An unspent P2PKH output is a UTXO. It means:

There is value here. Whoever can provide the corresponding public key and signature in the future can spend it.

When a wallet spends it, it creates an input and provides the signature and public key. The old UTXO is consumed, and new outputs are created.

Why Understanding P2PKH Matters for BSV Development

Even if you primarily use SDKs and wallet interfaces, understanding P2PKH is valuable because it ties together several core concepts:

  • Private key
  • Public key
  • Address
  • Public key hash
  • Locking script
  • Unlocking script
  • Signature verification
  • UTXO spending

Once you understand P2PKH, learning about OP_RETURN, multisig, custom scripts, and token state outputs becomes clearer.

P2PKH Is Not the Only Script

P2PKH is a common template, but not the only way. BSV Script can express many more conditions, such as:

  • Multisignature
  • Hash locks
  • Custom business scripts
  • Data outputs
  • Token protocol outputs

But P2PKH is the best template for beginners to understand ordinary payments.

Common Misconceptions for Beginners

  • P2PKH is not an account model.
  • An address is usually not the public key itself, but an encoding of the public key hash.
  • A P2PKH output must be unlocked by a signature and public key in the future.
  • P2PKH is a template for ordinary payments, not the only format for all BSV transactions.
  • Both public key hash matching and signature verification must pass.
  • The locking condition is in the output during receipt; the unlocking material is in the input during spending.

References

Recommended articles