1

This is the address information:

bitcoin-cli validateaddress n35oDVMPNkHRzBKy7q9RDB7r5e8qbVa9SW
{
  "isvalid": true,
  "address": "n35oDVMPNkHRzBKy7q9RDB7r5e8qbVa9SW",
  "scriptPubKey": "76a914ec90ca28c0ec302e991fb1c8171bf49c0d3d05be88ac",
  "isscript": false,
  "iswitness": false
}
bitcoin-cli decodescript 76a914ec90ca28c0ec302e991fb1c8171bf49c0d3d05be88ac
{
  "asm": "OP_DUP OP_HASH160 ec90ca28c0ec302e991fb1c8171bf49c0d3d05be OP_EQUALVERIFY OP_CHECKSIG",
  "reqSigs": 1,
  "type": "pubkeyhash",
  "addresses": [
    "n35oDVMPNkHRzBKy7q9RDB7r5e8qbVa9SW"
  ],
  "p2sh": "2NFyoZJJuWpvyiHFirFqsQnPXXna6mtf4Li",
  "segwit": {
    "asm": "0 ec90ca28c0ec302e991fb1c8171bf49c0d3d05be",
    "hex": "0014ec90ca28c0ec302e991fb1c8171bf49c0d3d05be",
    "reqSigs": 1,
    "type": "witness_v0_keyhash",
    "addresses": [
      "tb1qajgv52xqasczaxglk8ypwxl5nsxn6pd7307tfg"
    ],
    "p2sh-segwit": "2MwgL2byHmKdRvfGhufKpJkpAvtDLpo1REs"
  }
}

Why are the 2 P2SH addresses also shown? Are they interchangeable? What do they have in common?

What is a "witness_v0_keyhash" address?

1

From bitcoin-cli help decodescript:

{
  "asm":"asm",          (string) Script public key
  "type":"type",        (string) The output type (e.g. nonstandard, pubkey, pubkeyhash, scripthash, multisig, nulldata, witness_v0_scripthash, witness_v0_keyhash, witness_unknown)
  "reqSigs": n,         (numeric) The required signatures
  "addresses": [        (json array of string)
     "address"          (string) bitcoin address
     ,...
  ],
  "p2sh":"str"          (string) address of P2SH script wrapping this redeem script (not returned if the script is already a P2SH).
  "segwit": {           (json object) Result of a witness script public key wrapping this redeem script (not returned if the script is a P2SH or witness).
    "asm":"str",        (string) String representation of the script public key
    "hex":"hexstr",     (string) Hex string of the script public key
    "type":"str",       (string) The type of the script public key (e.g. witness_v0_keyhash or witness_v0_scripthash)
    "reqSigs": n,       (numeric) The required signatures (always 1)
    "addresses": [      (json array of string) (always length 1)
      "address"         (string) segwit address
       ,...
    ],
    "p2sh-segwit":"str" (string) address of the P2SH script wrapping this witness redeem script.
}

Additional explanation, using your example:

n35oDVMPNkHRzBKy7q9RDB7r5e8qbVa9SW: this is a "legacy" pay-to-pubkey-hash address. Coins sent to this address are locked with the asm script you see in the output. They can be unlocked with a scriptSig that contains the public key that matches the hash, followed by a signature matching the public key.

p2sh: 2NFyoZJJuWpvyiHFirFqsQnPXXna6mtf4Li: This one is a bit confusing. It is still a "legacy" (not segwit) address, and it is a pay-to-script-hash address. Coins sent to this address are locked with a hash of the entire script you see above in asm. They are spent by pushing a scriptSig with the entire serialized script (DUP/HASH/EQUAL/CHECKSIG) followed by the public key and finally the signature.

segwit: tb1qajgv52xqasczaxglk8ypwxl5nsxn6pd7307tfg: Here is a segwit address. BIP141 defines a few segwit address types and this one, as you can see, is a pay-to-witness-pubkey-hash or witness_v0_keyhash or p2wpkh address. Coins sent to this address are locked with a hash of a public key only (along with a specific byte that indicates segregated witness). They are spent by pushing an EMPTY scriptSig and providing a witness stack that has the public key and signature.

p2sh-segwit: 2MwgL2byHmKdRvfGhufKpJkpAvtDLpo1REs: Another segwit address. This one, as you can see, is a NESTED pay-to-witness-pubkey-hash or p2wpkh-p2sh address. Coins sent to this address are locked with a hash of the witness program seen in the asm section of the segwit section. They are spent by providing the serialized witness program in a scriptSig and ALSO including a witness stack with public key and signature.

Summary

If you have one private key, you can spend coins sent to any of these four addresses.

| improve this answer | |
  • I generated my address, why should I use the others? Why are they the result of the decoded scriptPubKey? I don't get alternative addresses when I decode thePubkey script of a P2SH address, why? – Melk May 5 at 12:10
  • I should have been more clear in my "summary": all these address types in one way or another encode the script you passed in to the decode command. The rpc command does not know which address type you want, but it is overly helpful by not only decoding the script but also computing all the possible address types that use it. – pinhead May 5 at 12:14
  • Therefore, can I say that all these addresses use the script that I am decoding? – Melk May 5 at 12:21
  • 1
    Yes that is correct – pinhead May 5 at 12:22

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.