P2PKH

Genx Avatar

P2PKH stands for “Pay to Public Key Hash.” It’s a type of transaction that is widely used in Bitcoin and many other cryptocurrencies.

The idea behind P2PKH is to allow a person to send funds to another person’s Bitcoin address, which is derived from their public key. The sender doesn’t need to know the recipient’s public key; they just need the Bitcoin address.

Here’s a brief outline of how P2PKH works:

  1. Creating a Bitcoin address: The recipient generates a private-public key pair. The Bitcoin address is derived from the public key by applying a series of cryptographic hash functions (SHA-256 and RIPEMD-160). The final result is a 20-byte number that represents the Bitcoin address.
  2. Sending Bitcoin: When the sender wants to send Bitcoin to the recipient, they create a transaction output that locks the funds with a P2PKH script. The script essentially says “whoever can provide a public key that hashes to this Bitcoin address, and a digital signature that matches this public key, can spend these funds.”
  3. Spending Bitcoin: To spend the Bitcoin, the recipient must provide a signature script (input script) that includes their public key and a digital signature created with their private key. This is included in a new transaction that spends the previous transaction’s output.
  4. Verification: The Bitcoin network nodes or miners validate the transaction by checking the provided public key hashes to the expected Bitcoin address, and that the digital signature matches the provided public key. If these checks pass, the transaction is considered valid.

This mechanism provides a balance of privacy and security: the Bitcoin address can be shared publicly, but the public key is only revealed when the funds are spent, and the private key (which is required to spend the funds) is never revealed.