I'm studying Bitcoin protocol, and I'm able to create address by my bash script.

The addresses "P2PKH" and "P2PK" have the same procedure.

Compressed or uncompressed public key – SHA256 – RIPEMD160. When I create a transaction using createrawtransaction I can see that the protocol use P2PKH validation by default, and in listunspent I can find its scriptPubKey.

My question is: How the protocol (and where in the code) recognize the validation? I'd like to understand when the protocol add OP_PUSHBYTES[33] PBKEY OP_CHECKSIG instead of OP_DUP OP_HASH160 OP_PUSHBYTES[20] HASH160(PB) OP_EQUALVERIFY OP_CHECKSIG and How can I use P2PK instead of P2PKH?


For istance, my address is: (testnet)


Import my address (I don't have it in my wallet, I created this address from outside of bitcoin-core)

bitcoin-cli importaddress mwqCgoJBcyciRUawXerkvom8sbg3zkjrvV

then I mined 101 blocks

bitcoin-cli generatetoaddress 101 mwqCgoJBcyciRUawXerkvom8sbg3zkjrvV >> /dev/null

After that I check my UTXO:

bitcoin-cli listunspent 1 101 '["'mwqCgoJBcyciRUawXerkvom8sbg3zkjrvV'"]'
    "txid": "531dcfeea3f87feb4101bfea6fe91ffb0262072cb27acc56f885677ccca089cd",
    "vout": 0,
    "address": "mwqCgoJBcyciRUawXerkvom8sbg3zkjrvV",
    "label": "",
    "scriptPubKey": "76a914b2f58389a224c2fac62b51e78aad7ed058b50f5f88ac",
    "amount": 50.00000000,
    "confirmations": 101,
    "spendable": false,
    "solvable": false,
    "safe": true

retrieve the UTXO

bitcoin-cli getrawtransaction 531dcfeea3f87feb4101bfea6fe91ffb0262072cb27acc56f885677ccca089cd 2 | jq

      "value": 50,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 b2f58389a224c2fac62b51e78aad7ed058b50f5f OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914b2f58389a224c2fac62b51e78aad7ed058b50f5f88ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [


Why I have P2PKH instead of P2PK? And how can have the hash of my Public key if I imported just address (HASH160(PB))? And the last question, I understand that if the wallet find the 1 as the first char it apply P2PKH by default. How Can I use P2PK instead (study purpose).

1 Answer 1


The protocol is not what decides the scriptPubKey, it's your wallet that creates the transaction. Your wallet chooses what scriptPubKey to use based on the address that it is given. It uses P2PKH for 1... addresses because that's the scriptPubKey that that type of address specifies. It cannot use those addresses for P2PK because they do not contain enough information for P2PK - they only have the hash160 of the pubkey, not the full pubkey itself. Additionally, using a different scriptPubKey for those addresses would mean that the Bitcoin is sent to a scriptPubKey that the receiver is not necessarily watching.

The same applies to all of the other address types - the address type specifies the scriptPubKey to create.

Why I have P2PKH instead of P2PK?

Because that's the address type you imported. You are using regtest, so P2PKH addresses begin with m or n.

And how can have the hash of my Public key if I imported just address (HASH160(PB))?

The address specifies the hash.

And the last question, I understand that if the wallet find the 1 as the first char it apply P2PKH by default. How Can I use P2PK instead (study purpose).

You cannot. P2PK does not have an address type. There are no P2PK addresses.

Some software and blockchain explorers will show P2PKH addresses for P2PK scriptPubKeys, but this is incorrect. P2PK scriptPubKeys do not have a corresponding address.

  • Thanks for your comments, I updated my question. thanks again
    – monkeyUser
    Dec 11, 2020 at 17:28
  • 1
    I've updated my answer to answer your questions.
    – Ava Chow
    Dec 11, 2020 at 18:37
  • 2
    There is no address for that scriptPubKey. It is incorrect for the block explorer to be showing that. You can create an address for a given pubkey by hashing it, however that address will not correspond to a P2PK scriptPubKey. You can read en.bitcoin.it/wiki/… for some more information on how an address can be created from a pubkey.
    – Ava Chow
    Dec 11, 2020 at 19:11
  • 2
    It is not possible to give a pubkey as an address, pubkeys are not addresses and do not have addresses. You cannot create a P2PK transaction in Bitcoin Core.
    – Ava Chow
    Dec 11, 2020 at 19:28
  • 1
    @monkeyUser Bitcoin never had any address type corresponding to P2PK. What it did (very briefly) have was a way to ask another node (over the P2P network!) how to pay it, and it would respond not with an address, but with a scriptPubKey directly. That scriptPubKey could be a P2PK. But since the introduction of bitcoin addresses (before the first release!), they have never had the ability to encode a P2PK script. Dec 11, 2020 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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