<p>I have written a program in Python3 that allows you to search any address on bitcoin core whether it belongs to your wallet or not.</p>
<p>Here is the github link:</p>
<p><a href="https://github.com/ORP967/Bitcoin_Core_RPC_par_address" rel="nofollow noreferrer">https://github.com/ORP967/Bitcoin_Core_RPC_par_address</a></p>
<p>If you have any improvements to it let me know.</p>

CC BY-SA 4.0
2022-01-23T22:43:10.667Z
2022-01-23T22:43:10.667Z
ORP967
<p>The bitcoin <code>listunspent</code> rpc call does exactly what you are looking for:</p>
<blockquote>
<p>listunspent ( minconf maxconf [&quot;address&quot;,...] include_unsafe
query_options )</p>
<p>Returns array of unspent transaction outputs with between minconf and
maxconf (inclusive) confirmations.</p>
<p>Optionally filter to only include txouts paid to specified addresses.</p>
</blockquote>
<p><a href="https://developer.bitcoin.org/reference/rpc/listunspent.html" rel="nofollow noreferrer">Source.</a></p>

CC BY-SA 4.0
2022-10-18T09:45:40.377Z
However, `listunspent` works only if there is a wallet loaded, so it is not really useful for an explorer.
OptOut
CC BY-SA 4.0
2021-12-12T15:59:54.533Z
2021-12-12T15:59:54.533Z
SickGuy
<p>There isn't really a way to do this efficiently, as Bitcoin Core is not designed for that.</p>

<p>You can search using the the <code>scantxoutset</code> RPC command, but all that is doing is iterating over the entire database and returning matching entries (it's more powerful than just by address though; it can for example search for an xpub + derivation path too).</p>

<p>There is some work around adding support for an optional (and separate) address-based index to Bitcoin Core, but that will at the earliest be for v0.21.</p>

<p>Other than that, there are a number of other software packages that can build such an index (independently from Bitcoin Core).</p>

CC BY-SA 4.0
2020-03-19T17:41:02.060Z
OK. Thanks for your reply. I wonder, however, how does a wallet know where to get the inputs for an outgoing transaction efficiently if there is only the "scantxoutset" command? Do they have a parallel database where they sort the UTXO set by address instead of tx_id?
Oscar Serna
CC BY-SA 4.0
2020-03-19T17:58:18.057Z
The wallet maintains its own list of UTXOs (which is just a tiny set), which is built by simply observing every block.
Pieter Wuille
CC BY-SA 4.0
2020-03-19T19:15:37.593Z
So the "balance" of an address is calculated through querying the parsed database version of the blockchain itself, and the UTXO set is used only to check double spending?
Oscar Serna
CC BY-SA 4.0
2020-03-19T19:18:17.387Z
"Balance of an address" is an illusion created by block explorer websites. Full nodes or wallets don't care about the concept - they just need a set of UTXOs that are yours. Apart from accounting reasons, knowing the balance of an address is meaningless as you still need to know the actual UTXOs in order to spend them. Furthermore, taking common privacy advice into account, addresses shouldn't be used for more than one payment, so you need the aggregate of all your addresses in any case.
Pieter Wuille
CC BY-SA 4.0
2020-03-19T19:46:13.913Z
sorry, but that is not helpful. I understand what you are saying, but my question is not an abstract one. I just want to know how to get the utxo of an address so I can build my own raw transactions without the need of an external block explorer. I am running my own full node, so I should be able to achieve this myself, but I'm not sure how to do it. Should I parse the blockchain to a database, query the address for all historical transactions and then check the chainstate to check which ones are spendable? Or can I achieve this efficiently (in a second max) by only looking at the chainstate?
Oscar Serna
CC BY-SA 4.0
2020-03-19T19:47:41.830Z
Using scantxoutset is as fast as you can with Bitcoin Core today (it may take minutes, but not hours), as it scans the UTXO set and not the entire blockchain. If you need something faster, you'll need other software.
Pieter Wuille
CC BY-SA 4.0
2020-03-19T19:52:43.843Z
Alternatively, and this may not apply, but the most efficient approach is creating a watch-only wallet with the addresses you care about, and then using wallet RPCs to build raw transactions (or the more modern PSBT style approach). This means a single lengthy rescan of the chain, but after that it will effectively remain up to date for free.
Pieter Wuille
CC BY-SA 4.0
2020-03-19T05:47:47.297Z
2020-03-19T05:47:47.297Z
Pieter Wuille
<p>I am new in the blockchain field, and I am trying to build my own block explorer from scratch to really learn about Bitcoin. I am currently running a full node in a raspberry pi, and I have already decoded the chainstate/UTXO-set with a levelDB library for Node.js. The content of this database is not exactly what I found in the documentation around, but led me well enough to fully decode this database.</p>

<p>Basically, the keys are the transaction ids with the index of the output, and the values contain the height, wether it is a coinbase transaction or not, the amount, and the address (before the base58 encoding) of every utxo. </p>

<p>However, I don't really know how to query this database in an efficient way to get all the utxos for a specific address without scanning the whole chainstate. It took me about 10 minutes to get all the utxos of a single address which is totally unacceptable. </p>

<p>I guess my specific question is how do I query this database through the values instead of the keys? Or if there is a better way to do this, maybe through the blockchain itself? maybe to an RPC bitcoin-cli call?</p>

<utxo><balance><query>
How to query all utxos of an address from a full node?
Oscar Serna
# How to query all utxos of an address from a full node?

(Asked by: username_0 on 2020-03-19)

I am new in the blockchain field, and I am trying to build my own block explorer from scratch to really learn about Bitcoin. I am currently running a full node in a raspberry pi, and I have already decoded the chainstate/UTXO-set with a levelDB library for Node.js. The content of this database is not exactly what I found in the documentation around, but led me well enough to fully decode this database.

Basically, the keys are the transaction ids with the index of the output, and the values contain the height, wether it is a coinbase transaction or not, the amount, and the address (before the base58 encoding) of every utxo.

However, I don't really know how to query this database in an efficient way to get all the utxos for a specific address without scanning the whole chainstate. It took me about 10 minutes to get all the utxos of a single address which is totally unacceptable.

I guess my specific question is how do I query this database through the values instead of the keys? Or if there is a better way to do this, maybe through the blockchain itself? maybe to an RPC bitcoin-cli call?

**Tags:** utxo, balance, query


---

## 3 answers

### Answer by username_4 on 2020-03-19. Score: 5 | Accepted answer

There isn't really a way to do this efficiently, as Bitcoin Core is not designed for that.

You can search using the the `scantxoutset` RPC command, but all that is doing is iterating over the entire database and returning matching entries (it's more powerful than just by address though; it can for example search for an xpub + derivation path too).

There is some work around adding support for an optional (and separate) address-based index to Bitcoin Core, but that will at the earliest be for v0.21.

Other than that, there are a number of other software packages that can build such an index (independently from Bitcoin Core).

> **Comments:**
> **username_0**: OK. Thanks for your reply. I wonder, however, how does a wallet know where to get the inputs for an outgoing transaction efficiently if there is only the "scantxoutset" command? Do they have a parallel database where they sort the UTXO set by address instead of tx_id?  
> **username_4**: The wallet maintains its own list of UTXOs (which is just a tiny set), which is built by simply observing every block.  
> **username_0**: So the "balance" of an address is calculated through querying the parsed database version of the blockchain itself, and the UTXO set is used only to check double spending?  
> **username_4**: "Balance of an address" is an illusion created by block explorer websites. Full nodes or wallets don't care about the concept - they just need a set of UTXOs that are yours. Apart from accounting reasons, knowing the balance of an address is meaningless as you still need to know the actual UTXOs in order to spend them. Furthermore, taking common privacy advice into account, addresses shouldn't be used for more than one payment, so you need the aggregate of all your addresses in any case.  
> **username_0**: sorry, but that is not helpful. I understand what you are saying, but my question is not an abstract one. I just want to know how to get the utxo of an address so I can build my own raw transactions without the need of an external block explorer. I am running my own full node, so I should be able to achieve this myself, but I'm not sure how to do it. Should I parse the blockchain to a database, query the address for all historical transactions and then check the chainstate to check which ones are spendable? Or can I achieve this efficiently (in a second max) by only looking at the chainstate?  
> **username_4**: Using scantxoutset is as fast as you can with Bitcoin Core today (it may take minutes, but not hours), as it scans the UTXO set and not the entire blockchain. If you need something faster, you'll need other software.  
> **username_4**: Alternatively, and this may not apply, but the most efficient approach is creating a watch-only wallet with the addresses you care about, and then using wallet RPCs to build raw transactions (or the more modern PSBT style approach). This means a single lengthy rescan of the chain, but after that it will effectively remain up to date for free.  

---

### Answer by username_1 on 2022-01-23. Score: 0

I have written a program in Python3 that allows you to search any address on bitcoin core whether it belongs to your wallet or not.

Here is the github link:

<https://github.com/username_1/Bitcoin_Core_RPC_par_address>

If you have any improvements to it let me know.


---

### Answer by username_2 on 2021-12-12. Score: 0

The bitcoin `listunspent` rpc call does exactly what you are looking for:

> listunspent ( minconf maxconf ["address",...] include\_unsafe
> query\_options )
>
> Returns array of unspent transaction outputs with between minconf and
> maxconf (inclusive) confirmations.
>
> Optionally filter to only include txouts paid to specified addresses.

[Source.](https://developer.bitcoin.org/reference/rpc/listunspent.html)

> **Comments:**
> **username_3**: However, `listunspent` works only if there is a wallet loaded, so it is not really useful for an explorer.  

---

