<p>From <code>bitcoin-cli help decodescript</code>:</p>

<pre><code>{
  "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.
}
</code></pre>

<p>Additional explanation, using your example:</p>

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

<p><code>p2sh: 2NFyoZJJuWpvyiHFirFqsQnPXXna6mtf4Li</code>: 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 <code>asm</code>. They are spent by pushing a <code>scriptSig</code> with the entire serialized script (DUP/HASH/EQUAL/CHECKSIG) followed by the public key and finally the signature.</p>

<p><code>segwit: tb1qajgv52xqasczaxglk8ypwxl5nsxn6pd7307tfg</code>:  Here is a segwit address. <a href="https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#Examples" rel="nofollow noreferrer">BIP141</a> defines a few segwit address types and this one, as you can see, is a pay-to-witness-pubkey-hash or <code>witness_v0_keyhash</code> 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 <code>scriptSig</code> and providing a <code>witness</code> stack that has the public key and signature.</p>

<p><code>p2sh-segwit: 2MwgL2byHmKdRvfGhufKpJkpAvtDLpo1REs</code>: 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 <em>witness program</em> seen in the <code>asm</code> section of the <code>segwit</code> section. They are spent by providing the serialized witness program in a <code>scriptSig</code> and ALSO including a witness stack with public key and signature.</p>

<h2>Summary</h2>

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

CC BY-SA 4.0
2020-05-05T12:10:16.683Z
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?
MaXbeMan
CC BY-SA 4.0
2020-05-05T12:14:07.477Z
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
CC BY-SA 4.0
2020-05-05T12:21:52.773Z
Therefore, can I say that all these addresses use the script that I am decoding?
MaXbeMan
CC BY-SA 4.0
2020-05-05T12:22:52.907Z
Yes that is correct
pinhead
CC BY-SA 4.0
2020-05-05T11:31:40.247Z
2020-05-05T11:38:19.530Z
2020-05-05T11:38:19.530Z
pinhead
<p>This is the address information:</p>

<pre><code>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"
  }
}
</code></pre>

<blockquote>
  <p>Why are the 2 P2SH addresses also shown? Are they interchangeable?
  What do they have in common?</p>
  
  <p>What is a "witness_v0_keyhash" address?</p>
</blockquote>

<address><segregated-witness><public-key><p2pkh>
Decodescript for a Testnet pubkey hash address
MaXbeMan
# Decodescript for a Testnet pubkey hash address

(Asked by: username_0 on 2020-05-05)

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?

**Tags:** address, segregated-witness, public-key, p2pkh


---

## 1 answers

### Answer by username_1 on 2020-05-05. Score: 1 | Accepted answer

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](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#Examples) 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.

> **Comments:**
> **username_0**: 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?  
> **username_1**: 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.  
> **username_0**: Therefore, can I say that all these addresses use the script that I am decoding?  
> **username_1**: Yes that is correct  

---

