2

A Bitcoin address is created with Base58Check encoding and it requires a version prefix, such as 0x00 for a P2PKH(pay-to-public-key-hash) address, 0x05 for a P2SH(pay-to-script-hash) address.

Does the version prefix of a Bitcoin address force the type of transactions the address may treat, or is it just for indicating the appropriate one?

In other words, can one do:

  1. Generate a ECDSA key pair.
  2. Create a Bitcoin address with it, with a version prefix 0x05.
  3. The generated address is a P2SH(-like) address; at least its format is.
  4. Make a P2PKH transaction with it.
3

Since addresses are only human abstractions and do not actually exist on the network, no, addresses do not force the type of transaction that you can create with the data provided in an address. There would be no way to enforce that. However creating a transaction that does not use the type that the address specifies is a good way to lose funds because the way to spend those outputs are different.

So yes, you can take a P2SH address and create a transaction with a P2PKH output that has the same data that the P2SH address provided. But the person who controls that P2SH address is not going to be able to spend the coins from the P2PKH output since the requirements for spending will be different.

2

It just indicates the appropriate kind. The version byte doesn't actually appear in the final transaction.

You could certainly do what you propose, though you'll have to modify your client software to achieve 4, since by default it is going to try to create a P2SH transaction when it sees version byte 0x5. But the resulting transaction would be the same transaction as if you'd used a 0x0 address from the outset.

2

The existing answers to this questions are good, but I want to give a slightly different perspective.

An address is a shorthand notation for one specific scriptPubKey to use in a transaction output.

P2PKH addresses are shorthands for OP_DUP OP_HASH160 <keyhash> OP_EQUALVERIFY OP_CHECKSIG scripts. To spend these, you need to have a private key for a public key whose Hash160 is .

P2SH addresses are shorthands for OP_HASH160 <scripthash> OP_EQUAL scripts. Due to BIP16, you need a script whose Hash160 is which you can sign for in order to spend these.

Taking a hash of a public key and then using that as a scripthash in a P2SH address is nonsensical as you have no script with that hash (and much less one you can sign for). It's not very different from taking a P2PKH address and changing some byte and the checksum in it - obviously you won't be able to spend it, as it is not your address but a random other address. The same is true if you use the wrong prefix: you're randomly modifying the address in a way that results in it likely being spendable by nobody.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.