<p>Not all scriptPubKeys correspond to an address. The <code>address</code> field is provided for those that do, and is omitted for those that don't. Your example contains a P2PK scriptPubKey which does not have a corresponding address.</p>
<p>Some blockchain explorers may extract the pubkey from a P2PK output and compute a corresponding address, but that is not technically correct. Such an address would result in a P2PKH scriptPubKey, not P2PK.</p>

CC BY-SA 4.0
2021-12-27T07:16:42.793Z
Am I correct in assuming that if `address` is not provided, it means the `address` cannot be "constructed" correctly?
Dr. Strangelove
CC BY-SA 4.0
2021-12-27T17:32:06.667Z
@Hamed Yes. If `address` does not exist, the scriptPubKey has no corresponding address.
Ava Chow
CC BY-SA 4.0
2021-12-27T17:37:27.083Z
Thank you. Does this apply only to P2PK, or I can generalize it to P2SH, P2SHH, and P2WPKH?
Dr. Strangelove
CC BY-SA 4.0
2021-12-27T22:13:40.913Z
You can generalize it to all scriptPubKeys. If the scriptPubKey has a corresponding address, then there will be an address present. Note that there is no address for this P2PK scriptPubKey because all P2PK scriptPubKeys do not have addresses. Likewise, all P2PKH scriptPubKeys have addresses.
Ava Chow
CC BY-SA 4.0
2021-12-27T05:35:53.173Z
2021-12-27T05:35:53.173Z
Ava Chow
<p>Given that <code>address</code> is a &quot;convenience&quot; field, it makes sense that it is not provided by default in many transactions. However, it seems to be possible to <a href="https://bitcoin.stackexchange.com/a/48449/129532">extract <code>address</code> from <code>hex</code></a>. I am wondering if I can get this address from <code>bitcoin</code> client applications (e.g., <code>bitcoin-qt</code>), ideally via the REST API.</p>
<p>An example block I am looking at is the block with height 100:</p>
<pre><code>{
    &quot;hash&quot;: &quot;000000007bc154e0fa7ea32218a72fe2c1bb9f86cf8c9ebf9a715ed27fdb229a&quot;,
    &quot;confirmations&quot;: 715831,
    &quot;height&quot;: 100,
    &quot;version&quot;: 1,
    &quot;versionHex&quot;: &quot;00000001&quot;,
    &quot;merkleroot&quot;: &quot;2d05f0c9c3e1c226e63b5fac240137687544cf631cd616fd34fd188fc9020866&quot;,
    &quot;time&quot;: 1231660825,
    &quot;mediantime&quot;: 1231656204,
    &quot;nonce&quot;: 1573057331,
    &quot;bits&quot;: &quot;1d00ffff&quot;,
    &quot;difficulty&quot;: 1,
    &quot;chainwork&quot;: &quot;0000000000000000000000000000000000000000000000000000006500650065&quot;,
    &quot;nTx&quot;: 1,
    &quot;previousblockhash&quot;: &quot;00000000cd9b12643e6854cb25939b39cd7a1ad0af31a9bd8b2efe67854b1995&quot;,
    &quot;nextblockhash&quot;: &quot;00000000b69bd8e4dc60580117617a466d5c76ada85fb7b87e9baea01f9d9984&quot;,
    &quot;strippedsize&quot;: 215,
    &quot;size&quot;: 215,
    &quot;weight&quot;: 860,
    &quot;tx&quot;: [
        {
            &quot;txid&quot;: &quot;2d05f0c9c3e1c226e63b5fac240137687544cf631cd616fd34fd188fc9020866&quot;,
            &quot;hash&quot;: &quot;2d05f0c9c3e1c226e63b5fac240137687544cf631cd616fd34fd188fc9020866&quot;,
            &quot;version&quot;: 1,
            &quot;size&quot;: 134,
            &quot;vsize&quot;: 134,
            &quot;weight&quot;: 536,
            &quot;locktime&quot;: 0,
            &quot;vin&quot;: [
                {
                    &quot;coinbase&quot;: &quot;04ffff001d014d&quot;,
                    &quot;sequence&quot;: 4294967295
                }
            ],
            &quot;vout&quot;: [
                {
                    &quot;value&quot;: 50.00000000,
                    &quot;n&quot;: 0,
                    &quot;scriptPubKey&quot;: {
                        &quot;asm&quot;: &quot;04e70a02f5af48a1989bf630d92523c9d14c45c75f7d1b998e962bff6ff9995fc5bdb44f1793b37495d80324acba7c8f537caaf8432b8d47987313060cc82d8a93 OP_CHECKSIG&quot;,
                        &quot;hex&quot;: &quot;4104e70a02f5af48a1989bf630d92523c9d14c45c75f7d1b998e962bff6ff9995fc5bdb44f1793b37495d80324acba7c8f537caaf8432b8d47987313060cc82d8a93ac&quot;,
                        &quot;type&quot;: &quot;pubkey&quot;
                    }
                }
            ],
            &quot;hex&quot;: &quot;01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d014dffffffff0100f2052a01000000434104e70a02f5af48a1989bf630d92523c9d14c45c75f7d1b998e962bff6ff9995fc5bdb44f1793b37495d80324acba7c8f537caaf8432b8d47987313060cc82d8a93ac00000000&quot;
        }
    ]
}
</code></pre>

<bitcoin-core><json-rpc><p2pk>
Get Address from pubkey scriptPubKey
Dr. Strangelove
# Get Address from pubkey scriptPubKey

(Asked by: username_0 on 2021-12-27)

Given that `address` is a "convenience" field, it makes sense that it is not provided by default in many transactions. However, it seems to be possible to [extract `address` from `hex`](https://bitcoin.stackexchange.com/a/48449/129532). I am wondering if I can get this address from `bitcoin` client applications (e.g., `bitcoin-qt`), ideally via the REST API.

An example block I am looking at is the block with height 100:

```
{
    "hash": "000000007bc154e0fa7ea32218a72fe2c1bb9f86cf8c9ebf9a715ed27fdb229a",
    "confirmations": 715831,
    "height": 100,
    "version": 1,
    "versionHex": "00000001",
    "merkleroot": "2d05f0c9c3e1c226e63b5fac240137687544cf631cd616fd34fd188fc9020866",
    "time": 1231660825,
    "mediantime": 1231656204,
    "nonce": 1573057331,
    "bits": "1d00ffff",
    "difficulty": 1,
    "chainwork": "0000000000000000000000000000000000000000000000000000006500650065",
    "nTx": 1,
    "previousblockhash": "00000000cd9b12643e6854cb25939b39cd7a1ad0af31a9bd8b2efe67854b1995",
    "nextblockhash": "00000000b69bd8e4dc60580117617a466d5c76ada85fb7b87e9baea01f9d9984",
    "strippedsize": 215,
    "size": 215,
    "weight": 860,
    "tx": [
        {
            "txid": "2d05f0c9c3e1c226e63b5fac240137687544cf631cd616fd34fd188fc9020866",
            "hash": "2d05f0c9c3e1c226e63b5fac240137687544cf631cd616fd34fd188fc9020866",
            "version": 1,
            "size": 134,
            "vsize": 134,
            "weight": 536,
            "locktime": 0,
            "vin": [
                {
                    "coinbase": "04ffff001d014d",
                    "sequence": 4294967295
                }
            ],
            "vout": [
                {
                    "value": 50.00000000,
                    "n": 0,
                    "scriptPubKey": {
                        "asm": "04e70a02f5af48a1989bf630d92523c9d14c45c75f7d1b998e962bff6ff9995fc5bdb44f1793b37495d80324acba7c8f537caaf8432b8d47987313060cc82d8a93 OP_CHECKSIG",
                        "hex": "4104e70a02f5af48a1989bf630d92523c9d14c45c75f7d1b998e962bff6ff9995fc5bdb44f1793b37495d80324acba7c8f537caaf8432b8d47987313060cc82d8a93ac",
                        "type": "pubkey"
                    }
                }
            ],
            "hex": "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d014dffffffff0100f2052a01000000434104e70a02f5af48a1989bf630d92523c9d14c45c75f7d1b998e962bff6ff9995fc5bdb44f1793b37495d80324acba7c8f537caaf8432b8d47987313060cc82d8a93ac00000000"
        }
    ]
}

```

**Tags:** bitcoin-core, json-rpc, p2pk


---

## 1 answers

### Answer by username_1 on 2021-12-27. Score: 2 | Accepted answer

Not all scriptPubKeys correspond to an address. The `address` field is provided for those that do, and is omitted for those that don't. Your example contains a P2PK scriptPubKey which does not have a corresponding address.

Some blockchain explorers may extract the pubkey from a P2PK output and compute a corresponding address, but that is not technically correct. Such an address would result in a P2PKH scriptPubKey, not P2PK.

> **Comments:**
> **username_0**: Am I correct in assuming that if `address` is not provided, it means the `address` cannot be "constructed" correctly?  
> **username_1**: @Hamed Yes. If `address` does not exist, the scriptPubKey has no corresponding address.  
> **username_0**: Thank you. Does this apply only to P2PK, or I can generalize it to P2SH, P2SHH, and P2WPKH?  
> **username_1**: You can generalize it to all scriptPubKeys. If the scriptPubKey has a corresponding address, then there will be an address present. Note that there is no address for this P2PK scriptPubKey because all P2PK scriptPubKeys do not have addresses. Likewise, all P2PKH scriptPubKeys have addresses.  

---

