<p>The <code>&quot;address&quot;</code> field in the Bitcoin Core RPC output is present for all transaction outputs for which a corresponding address exists. In the first 10000 blocks there are lots of pay-to-public-key (P2PK) outputs, which while possible to construct internally in wallet software, don't have a corresponding address format that allows instructing a payer to create such an output.</p>
<p>The existing address types in Bitcoin today are:</p>
<ul>
<li>pay-to-pubkey-hash (P2PKH)</li>
<li>pay-to-script-hash (P2SH)</li>
<li>native witness addresses, for:
<ul>
<li>pay-to-witness-public-key-hash (P2WPKH)</li>
<li>pay-to-witness-script-hash (P2WSH)</li>
<li>pay-to-taproot (P2TR)</li>
</ul>
</li>
</ul>
<p>Whenever you inspect any output whose scriptPubKey matches any of these address types, the RPC output will report the address. But scriptPubKeys are free form byte arrays, and there is no strict requirement that they follow the structure encoded by any of the defined address types.</p>
<p>The <code>&quot;addresses&quot;</code> is older, and was deprecated and removed. Its purpose was listing the individual participants in bare multisig outputs. Such outputs predate the introduction of P2SH in 2012, and were never widespread. Today they're effectively unusable.</p>
<p>For documentation of Bitcoin Core's RPC, see the <code>help</code> RPC command, or <a href="https://bitcoincore.org" rel="nofollow noreferrer">https://bitcoincore.org</a>. The <a href="https://bitcoin.org" rel="nofollow noreferrer">https://bitcoin.org</a> website is unrelated to Bitcoin Core, and its information is often outdated.</p>
<p>The <code>&quot;desc&quot;</code> field reports information about the output in &quot;output descriptor&quot; notation. This format is described in BIP380 and the following BIPs, and Bitcoin Core documentation about it can be found in its doc directory: <a href="https://github.com/bitcoin/bitcoin/tree/master/doc/descriptors.md" rel="nofollow noreferrer">https://github.com/bitcoin/bitcoin/tree/master/doc/descriptors.md</a>. And indeed, <code>pk()</code> stands for public key, indicating a P2PK output with the argument as public key.</p>

CC BY-SA 4.0
2023-02-18T16:53:52.780Z
thanks that's incredibly helpful!  I also just realised I could use bitcoinrpc's deriveaddresses(tx['vout']['scriptPubKey']['desc']) which seems to either return addresses or throw an JSONRPCException if no addresses are associated to the vout
d3wannabe
CC BY-SA 4.0
2023-02-18T17:50:41.477Z
You can also check if the descriptor is of the form `addr()`, `pkh()`, `wpkh()`, `wsh()`, `sh()`,or `tr()`. Those have associated addresses.
Pieter Wuille
CC BY-SA 4.0
2023-02-18T16:42:33.703Z
2023-02-18T17:04:25.643Z
2023-02-18T17:04:25.643Z
Pieter Wuille
<p>I'm trying to write a simple python implementation using bitcoinrpc to extract the address <strong>receiving</strong> a transaction but...</p>
<ol>
<li><p>I'm not sure why certain fields are only accessible inconsistently.  E.g. <code>tx['vout']['scriptPubKey']['address']</code> is accessible 43 times in transactions in the first 10,000 blocks (but doesn't exist on the other 10,075 occasions).  The <a href="https://developer.bitcoin.org/reference/rpc/decoderawtransaction.html" rel="nofollow noreferrer">documentation</a> mentions I should even find a <code>tx['vout']['scriptPubKey']['addresses']</code> (plural) field but I can access that 0 times in the first 10,000 blocks.  I understand that there are different transaction/script types and that may impact things, for example the 43 times I found an 'address' field, the <code>tx['vout']['scriptPubKey']['asm']</code> field for that transaction had this identical structure/opcodes: <code>OP_DUP OP_HASH160 12ab8dc588ca9d5787dde7eb29569da63c3a238c OP_EQUALVERIFY OP_CHECKSIG</code>.  I also notice that fields like <code>tx['vout']['scriptPubKey']['asm']</code> and <code>tx['vout']['scriptPubKey']['desc']</code> are at least always present so I'm hoping it's possible to extract the receiver address from them somehow?  At least for a subset of the possible types of scripts?  If so, does anyone know the best place to find a definitive list of the valid types of scripts and for which I could extract the addresses?</p>
</li>
<li><p>The &quot;desc&quot; field has a structure like <code>'desc': 'pk(04b0db59592289864233ce40cf1dc7420e8b5e290b4402bd203545d330ece6ba841ffef40fa62b76596688a46e70b284f57566766b7d8bf75274b343164bafc8a3)#ef9sgeu5'</code> but I'm struggling to find a description of the format used - e.g. does pk stand for public key?</p>
</li>
</ol>
<p>Thanks for any thoughts at all</p>

<transactions><address><python>
Retrieving bitcoin address of the receiver of a transaction with bitcoinrpc
d3wannabe
# Retrieving bitcoin address of the receiver of a transaction with bitcoinrpc

(Asked by: username_0 on 2023-02-18)

I'm trying to write a simple python implementation using bitcoinrpc to extract the address **receiving** a transaction but...

1. I'm not sure why certain fields are only accessible inconsistently. E.g. `tx['vout']['scriptPubKey']['address']` is accessible 43 times in transactions in the first 10,000 blocks (but doesn't exist on the other 10,075 occasions). The [documentation](https://developer.bitcoin.org/reference/rpc/decoderawtransaction.html) mentions I should even find a `tx['vout']['scriptPubKey']['addresses']` (plural) field but I can access that 0 times in the first 10,000 blocks. I understand that there are different transaction/script types and that may impact things, for example the 43 times I found an 'address' field, the `tx['vout']['scriptPubKey']['asm']` field for that transaction had this identical structure/opcodes: `OP_DUP OP_HASH160 12ab8dc588ca9d5787dde7eb29569da63c3a238c OP_EQUALVERIFY OP_CHECKSIG`. I also notice that fields like `tx['vout']['scriptPubKey']['asm']` and `tx['vout']['scriptPubKey']['desc']` are at least always present so I'm hoping it's possible to extract the receiver address from them somehow? At least for a subset of the possible types of scripts? If so, does anyone know the best place to find a definitive list of the valid types of scripts and for which I could extract the addresses?
2. The "desc" field has a structure like `'desc': 'pk(04b0db59592289864233ce40cf1dc7420e8b5e290b4402bd203545d330ece6ba841ffef40fa62b76596688a46e70b284f57566766b7d8bf75274b343164bafc8a3)#ef9sgeu5'` but I'm struggling to find a description of the format used - e.g. does pk stand for public key?

Thanks for any thoughts at all

**Tags:** transactions, address, python


---

## 1 answers

### Answer by username_1 on 2023-02-18. Score: 3 | Accepted answer

The `"address"` field in the Bitcoin Core RPC output is present for all transaction outputs for which a corresponding address exists. In the first 10000 blocks there are lots of pay-to-public-key (P2PK) outputs, which while possible to construct internally in wallet software, don't have a corresponding address format that allows instructing a payer to create such an output.

The existing address types in Bitcoin today are:

* pay-to-pubkey-hash (P2PKH)
* pay-to-script-hash (P2SH)
* native witness addresses, for:
  + pay-to-witness-public-key-hash (P2WPKH)
  + pay-to-witness-script-hash (P2WSH)
  + pay-to-taproot (P2TR)

Whenever you inspect any output whose scriptPubKey matches any of these address types, the RPC output will report the address. But scriptPubKeys are free form byte arrays, and there is no strict requirement that they follow the structure encoded by any of the defined address types.

The `"addresses"` is older, and was deprecated and removed. Its purpose was listing the individual participants in bare multisig outputs. Such outputs predate the introduction of P2SH in 2012, and were never widespread. Today they're effectively unusable.

For documentation of Bitcoin Core's RPC, see the `help` RPC command, or <https://bitcoincore.org>. The <https://bitcoin.org> website is unrelated to Bitcoin Core, and its information is often outdated.

The `"desc"` field reports information about the output in "output descriptor" notation. This format is described in BIP380 and the following BIPs, and Bitcoin Core documentation about it can be found in its doc directory: <https://github.com/bitcoin/bitcoin/tree/master/doc/descriptors.md>. And indeed, `pk()` stands for public key, indicating a P2PK output with the argument as public key.

> **Comments:**
> **username_0**: thanks that's incredibly helpful!  I also just realised I could use bitcoinrpc's deriveaddresses(tx['vout']['scriptPubKey']['desc']) which seems to either return addresses or throw an JSONRPCException if no addresses are associated to the vout  
> **username_1**: You can also check if the descriptor is of the form `addr()`, `pkh()`, `wpkh()`, `wsh()`, `sh()`,or `tr()`. Those have associated addresses.  

---

