P2PKH, or "Pay to Pubkey Hash" transactions in full form, are one specific type of payment in the Bitcoin Script. P2PKH has been used for BTC transactions since January 16, 2009, just one week after the first block in the Bitcoin blockchain was mined. This article will explain everything you need to know about P2PKH transactions.
How Does P2PKH Work?
P2PKH transactions are similar to P2PK transactions, in that both payment types only require the recipient to prove ownership of their public key in order to receive the funds. The primary difference is that P2PK transactions are sent directly to the recipient’s public key, whereas P2PKH transactions are sent to the hash of the recipient's pub key. A hash is the output that results from putting a specific input through a hash function.
In this way, P2PKH is designed to provide more security and convenience for sending and receiving funds on a blockchain’s peer to peer network. This is largely due to two main advantages: public key hashing and error detection.
Public Key Hashing
Public key hashing in P2PKH transactions ensures that public keys aren’t made visible to other users, prior to that pubkey's wallet spending funds. This creates an additional layer of encryption between the user’s private key and the public network, providing increased security.
In addition, using pubkey hashes, rather than the full-length public keys, is a bit more user-friendly. That’s because the pubkey hash is a shorter set of alphanumeric characters. In other words, the pub key hash is just shorter and easier to manage than the pubkey itself.
To create a P2PKH transaction, the person who will be receiving the funds shares their address with the sender. Note that an address is distinct from a pubkey hash. An address encodes a pubkey hash in a format that is easy to share and has built-in error detection, as well as an indicator at the beginning that denotes which network it belongs to. The error detection is achieved through a checksum (sometimes called hash sum) that helps the wallet software detect a typo and prevent funds from being lost forever.
Converting a pubkey into an address is a multi-step process. First, the pubkey is hashed twice, once with the SHA-256 algorithm and then the resulting hash is hashed again with with the RIPEMD-160 algorithm. This produces the "pubkey hash" that can be used to create a P2PKH transaction.
Converting the pubkey hash into an address requires several more steps. First, the version bytes (normally 0x00) are added to the beginning of the pubkey hash. That new string is then hashed yet again with SHA-256. The first four bytes (32 bits) of that resulting hash are added to the end of the previous RIPEMD-160 hash. This acts as the checksum. Then the whole string is converted from a byte string into a base58 encoding string. The result is an address.
If a blockchain’s software recognizes an address as invalid, it will not create a transaction to the encoded pubkey hash. Note that there’s a very small chance that the software will accept an invalid address but the probability is minuscule— roughly 1 in 4.29 Billion.
Thus, using pubkey hashes encoded as addresses, rather than pub keys, is incredibly effective at detecting and rejecting errors. This makes pub key hashes far easier to use from a user’s perspective than the full-form pubkey.
A Basic Example of a P2PKH Payment
Let’s suppose that Bob wants to send BTC to Alice with a P2PKH transaction. Before the transaction can begin, Alice must first generate a private key/public key pair. Then her public key is converted to a pubkey hash, which is then further converted into an address. Alice sends the address to Bob, and Bob sends the payment to Alice’s address.
At that point, anyone who provides a digital signature from the private key to match Alice’s public key, and thus Alice’s address, can gain control of the funds that Bob sent. Of course, if Alice has kept her private key secure, then she is the only person who can receive and spend the funds.
During this entire process, Bob and Alice only interact using pubkey hashes and addresses. As such, they never have to know or use the other’s public key. As noted above, this provides an extra layer of secure encryption between the private key and the wider public.
Advantages and Limitations
P2PKH is a useful way to send and receive payments on the Bitcoin network. Newer Bitcoin scripts have gained some adoption, but P2PKH still plays an important role in most transactions.
Security: P2PKH was first introduced along with P2PK as one of the original Bitcoin transaction types, although P2PKH is far more common today compared to P2PK. Users who have P2PKH format wallets don’t have to be as concerned with emerging security threats such as attacks from quantum computers, which are more likely to create vulnerabilities for P2PK format wallets.
Simplicity: Compared to pub keys in the P2PK format, P2PKH addresses are much shorter in length. This makes them easier to manage and use. As described earlier in the article, they also contain a checksum, which drastically decreases the chances of sending funds to the incorrect wallet.
Complexity: Due to the additional steps required in transaction formation, developers widely consider P2PKH to be more difficult to program than simple Bitcoin scripts like P2PK.
SegWit Compatibility: Bitcoin scripts such as P2SH and Bech32 were introduced after P2PKH. Their main advantage over P2PKH is SegWit compatibility. Although this wasn’t a big deal when SegWit first launched with low adoption rates, the SegWit protocol is now gaining more support. While P2PKH will certainly remain relevant for non-SegWit transactions, it’s overall usage may see a slight decline if more exchanges and wallets adopt SegWit.
Is P2PKH Still Used Today?
On May 22, 2010, Laszlo Hanyecz used P2PKH to pay someone 10,000 BTC for the delivery of two pizzas to his house. This inspired the popular “Bitcoin Pizza Day” that is now celebrated annually among the crypto community.
P2PKH is still a prominent transaction type on the Bitcoin network ten years later. Although other transaction types are more suitable for completing multi-sig transactions, P2PKH remains a highly secure option for Bitcoin users.
The easiest way to identify P2PKH transactions is via a blockchain explorer website like BTC.com. Transactions involving addresses that start with the number ‘1’ are either P2PK or P2PKH. You will likely find that these addresses comprise a large portion of recent transactions at any given time.
According to txstats.com, over 10.2 million BTC (more than 56 percent of the existing BTC supply) is currently held in P2PKH wallets. The total number of P2PKH unspent transaction outputs (UXTOs) has surpassed 52.2 million.
Komodo Developer Docs
Smart Chains are customizable blockchains launched with Komodo’s technology. Each Smart Chain is fully autonomous and exists just like any other independent blockchain project, with its own peer to peer network, blockchain consensus rules, and currency. Smart Chains are also customizable along 18 different parameters and come equipped with a built-in library of modules, including tokens, a decentralized stablecoin solution, a quantum security module, a decentralized oracle module, and much more.
Begin your blockchain journey with Komodo today.