Skip to main content
43 votes

What is P2PK, P2PKH, P2SH, P2WPKH - ELI5

P2PKH: "Pay To Public Key Hash" This is how transactions are made. You are requiring the sender to supply a valid signature (from the private key) and public key. The transaction output script will ...
Monstrum's user avatar
  • 1,334
26 votes

How to calculate transaction size before sending (Legacy Non-Segwit - P2PKH/P2SH)

Here are some calculations based on the Protocol Documentation. A Bitcoin Transaction is composed of the following: Version (4 Bytes) TxIn Count (1 ~ 9B) For each TxIn: Outpoint (36B) Script Length ...
rny's user avatar
  • 2,428
22 votes
Accepted

Why is P2PKH used instead of the simpler P2PK?

The original reason why addresses were a public key hashes is something you'll need to ask Satoshi. My guess however is that it was just shorter and more convenient (note that compressed public keys ...
Pieter Wuille's user avatar
20 votes

Why do you use Bitcoin addresses instead of public keys?

Yes, you could send bitcoins directly to the public key: in fact, both Pay-to-PubKey (P2PK) and Pay-to-PubKey-Hash (P2PKH) were introduced in the first Bitcoin release. IIRC, P2PK is still used for ...
Murch's user avatar
  • 77k
16 votes
Accepted

Is it possible to convert an address from p2pkh to p2sh?

Is it possible to covert a p2pkh adrress to a p2sh adress? Don't. Addresses are determined by the wallet. It's the receiver's wallet saying "I will accept payment when it arrives at address X". ...
Pieter Wuille's user avatar
15 votes

Why do you use Bitcoin addresses instead of public keys?

As @Murch correctly pointed out it is indeed possible to send bitcoin to either a public key or to the hash of a public key. The original motivation for using hashes of public keys was to shorten the ...
Benedikt Bünz's user avatar
13 votes
Accepted

Bech32 conversion to legacy P2PKH?

Is it safe to receive funds at this 1FJJd... address? Kind of. Your wallet knows the private key that corresponds to that address as it is the same private key for the bech32 address. However it does ...
Ava Chow's user avatar
  • 71.5k
11 votes
Accepted

How big is the input of a P2PKH transaction?

The first number does not include the prevout, sequence number, or the length byte for the scriptSig. It also uses 65 bytes for the public key (which is correct if it is uncompressed, but compressed ...
Pieter Wuille's user avatar
10 votes
Accepted

How did pay-to-pubkey hash come about? What is its history?

Pay to Public Key Hash has existed for the entirety of Bitcoin's life. P2PKH addresses have existed since the earliest release of Bitcoin. Creating P2PKH addresses and sending to P2PKH addresses was ...
Ava Chow's user avatar
  • 71.5k
10 votes
Accepted

How is Public Key extracted from (message, digital signature, address)

An algorithm called Public Key Recovery exists for ECDSA, which lets you construct the public keys for which a given pair of message and signature would be valid. To explain the algorithm, remember ...
Pieter Wuille's user avatar
10 votes

What is the largest multisig quorum currently possible?

The rules governing this depend on the type of script used and whether that script is in the output script, in a P2SH, in a P2WSH, or in P2TR. Additionally, the rules are more restrictive for ...
Ava Chow's user avatar
  • 71.5k
9 votes
Accepted

How can I cheaply consolidate P2PKH outputs?

There really is no better answer than "wait for fees to come down". That might not be the most satisfying answer, but fees were below 2 sat/vB only a month ago, and the vast majority of ...
Vojtěch Strnad's user avatar
8 votes
Accepted

How to generate legacy receiving address in Bitcoin core 0.19.x.x

From within the GUI, no, and this is intentional. There is no reason to use P2PKH addresses anymore. If you need backwards compatibility, then that's what the P2SH checkbox is for. But if you really ...
Ava Chow's user avatar
  • 71.5k
7 votes
Accepted

Is - a valid bitcoin address character

No, "-" is neither part of the base58 character set 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz used to encode non-segwit addresses, nor the bech32 character set ...
Murch's user avatar
  • 77k
7 votes
Accepted

Is there a way to convert a P2PKH address into P2TR?

Short answer: no, at least not via the key path (and using a script path would be less efficient than using P2WPKH instead) Longer answer: no, and even if it were possible, this would be a terrible ...
Pieter Wuille's user avatar
6 votes

Why is P2PKH used instead of the simpler P2PK?

The public key is first SHA256 hashed and then RipeMD160 hashed. A Bitcoin address is actually an encoded hash of the public key. A public key is 65 bytes long (0x04 + 64 bytes public key) or 33 ...
MCCCS's user avatar
  • 10.2k
6 votes
Accepted

Certain spent P2PKH outputs give error: Non-canonical DER signature

The requirement for canonical DER signatures was only added in the BIP66 softfork in 2015. Before that time, such non-canonical signatures were legal, and your transaction predates the BIP66 ...
Pieter Wuille's user avatar
6 votes
Accepted

Does a P2PKH transaction send to the hash of the uncompressed key or the compressed key?

As far as Bitcoin's consensus rules are concerned, compressed and uncompressed keys for the same private key, are distinct keys. The answer to your question is: whatever the receiver's wallet uses. As ...
Pieter Wuille's user avatar
5 votes
Accepted

If I was developing a Bitcoin wallet, should I support both legacy and compatibility addresses?

Displaying two would be justified if you were asking about a BC1 p2wpkh vs a 3xxx p2sh(p2wpkh) because not everything supports BC1 but its pretty good to use when supported. Displaying two isn't ...
G. Maxwell's user avatar
  • 7,727
5 votes
Accepted

How does this simple script use the OP_CHECKSIG opcode?

Let's run through the program. The stack starts as <A sig> <A pubkey>. You run OP_DUP. The stack is now <A sig> <A pubkey> <A pubkey>. You run OP_HASH160. The stack is ...
Pieter Wuille's user avatar
5 votes
Accepted

Why P2SH seems to be never smaller than 34 characters, unlike P2PKH?

Because Base58 initial 1s carry 8 bits of data, but P2SH addresses cannot be represented with a string with initial 1s so it starts with 3 which, like all other cases & characters, encodes 5.86 ...
MCCCS's user avatar
  • 10.2k
5 votes
Accepted

A question about the role of OP_DUP in the P2PK(H) transaction specification, and possibility of slightly smaller single address transactions

Re-reading your question, I realize my other answer may be besides the point. It is certainly possible that the scripting language's semantics would recognize this scenario and cause failure if ...
Pieter Wuille's user avatar
4 votes

Bech32 conversion to legacy P2PKH?

You can’t assume that any given software will be know to go searching for arbitrary encodings of the public key you’re “converting” to. Depending on the wallet software on the other end, your payment ...
Claris's user avatar
  • 15.5k
4 votes
Accepted

Why doesn't address contain a full scriptPubKey?

There are several reasons for this, some historical and some more recently: At first, addresses were probably not intended to cover everything Bitcoin Script could do. They were a fallback for the ...
Pieter Wuille's user avatar
4 votes

How did pay-to-pubkey hash come about? What is its history?

The earliest client by satoshi had both. P2PK was default for mining and payments received using the interactive IP-to-IP payment protocol; P2PKH was intended for use in non-interactive payments. ...
skang404's user avatar
  • 616
4 votes
Accepted

How is a locking script reliably detected as a P2PKH script?

The secret is that it is being interpreted as an opcode. Opcodes 0x01 through 0x4b (decimal 1 to 75) are opcodes that specify the length of the data being pushed after them, as their own numerical ...
Raghav Sood's user avatar
  • 17.2k
4 votes
Accepted

Why OP_DUP instead of providing the PubKey twice in P2PKH?

Unfortunately, that would not be secure. Imagine an output with scriptPubkey OP_HASH160 <hash(P1)> OP_EQUALVERIFY OP_CHECKSIG. Now anyone can spend such an output by generating their own key P2, ...
Pieter Wuille's user avatar
4 votes

tracking invoice address type migration

You can find the first on https://txstats.com/dashboard/db/utxo-set-repartition-by-output-type?orgId=1. For a version weighed by value you can look at the graphs of the individual output types on the ...
Pieter Wuille's user avatar
4 votes
Accepted

Is it possible to use a P2PKH output with a schnorr signature?

No, it is not possible to use Schnorr signatures with old output types. Current node software evaluating transactions expects an ECDSA signature for an input spending a P2PKH output. Putting a Schnorr ...
Murch's user avatar
  • 77k
4 votes

Why does SegWit implement new address formats?

There had to be a way to distinguish between segwit addresses and "legacy" addresses so that software could correctly identify the type of transaction it needed to create. The obvious ...
meshcollider's user avatar
  • 11.9k

Only top scored, non community-wiki answers of a minimum length are eligible