<p>There is no way to enable faster querying for arbitrary addresses than <code>scantxoutset</code> in bitcoind.</p>

<p>Explorers provide this functionality by maintaining a separate database of all addresses and transactions which is optimized for that kind of query. Bitcoin Core, on the other hand, is optimized for consensus related queries, which are largely a hashset lookup for a given input for a transaction.</p>

<p>You could try running something such as <a href="https://github.com/kyuupichan/electrumx" rel="nofollow noreferrer">ElectrumX</a>, which backs the electrum wallet, or <a href="https://github.com/bitpay/bitcore" rel="nofollow noreferrer">Bitcore</a>, which backs many of Bitpay's wallet and explorer services.</p>

CC BY-SA 4.0
2019-12-15T22:46:41.443Z
Thanks. Any chance of bitcore or electrumX using bitcoin core's data folder to avoid storing ~300 GB twice?
Pedro
CC BY-SA 4.0
2019-12-15T23:15:45.193Z
You can read the data from an existing installation, but any indexing program will have to duplicate it into its own database to actually be able to efficiently answer your queries.
Raghav Sood
CC BY-SA 4.0
2019-12-15T23:18:24.557Z
Yes, I read eletrumX's DB has ~30GB and can (and should) read the data from a bitcoin core full node. Checking now whether this is also de case for bitcore.
Pedro
CC BY-SA 4.0
2019-12-15T23:20:17.107Z
These are all solutions that operate on top of bitcoind, as that is still the source of truth - they simply add some indexing capabilities that extend the kind of queries you can perform. Your space usage will not really double, as bitcoind's stoage format is somewhat inefficient in favour of fast lookups for specific tx outputs. Traditional databases will do a more efficient job in a lot of cases
Raghav Sood
CC BY-SA 4.0
2021-11-17T19:18:43.703Z
Hi @Pedro Were you able to get this to work? I'm curious to know since I'm looking to do something similar.
kdas
CC BY-SA 4.0
2021-11-17T19:19:45.330Z
@RaghavSood "maintaining a separate database of all addresses and transactions"....how can I go about creating such a db myself?
kdas
CC BY-SA 4.0
2021-11-17T19:21:41.020Z
@kdas no fast and easy way to do it with only bitcoin core, you need to run an electrum server.
Pedro
CC BY-SA 4.0
2019-12-15T22:18:47.500Z
2019-12-15T22:18:47.500Z
Raghav Sood
<p>As some people have mentioned (eg. <a href="https://bitcoin.stackexchange.com/questions/50847/how-to-get-balance-of-tens-of-thousands-of-addresses">here</a>), the only way to get the balance of an address in bitcoin core was to import it as a watch-only address and rescan the blockchain. Starting with bitcoin core v0.17, we can use the <code>scantxoutset</code> command, however this is quite slow:</p>

<pre><code>&gt; time bitcoin-cli scantxoutset "start" "[\"addr(17Pu3CEx34YX8bpGATq45PfL2fGBCPcr2u)\"]"
{
  "success": true,
  "searched_items": 64162818,
  "unspents": [
    {
      "txid": "9796cee98fa88efcb9fdb954188d276b73d6e76719af6b5470ad23a2f744ecca",
      "vout": 1,
      "scriptPubKey": "76a91446255848182640edff4d178f365d7824513bc28d88ac",
      "desc": "addr(17Pu3CEx34YX8bpGATq45PfL2fGBCPcr2u)#x2q6xgrk",
      "amount": 0.02155141,
      "height": 607852
    }
  ],
  "total_amount": 0.02155141
}

real    0m42.419s
user    0m0.007s
sys 0m0.003s 
</code></pre>

<p>42 seconds is quite slow, I would like to get something comparable to block explorers (less than 2 seconds). Is it possible to achieve faster results with some advanced bitcoin core configuration?</p>

<p>Or, is there any open-source project I could use to index the UTXO set by address? Not sure if libbitcoin, bitcoinj, bitcoinJS, etc. are able to do this faster. Some tool block explorers might use to provide this service would be what I am looking for. </p>

<bitcoin-core><address><utxo><utxo-set><blockchain-explorer>
How to quickly get the balance of any bitcoin address? (with no third-party API)
Pedro
# How to quickly get the balance of any bitcoin address? (with no third-party API)

(Asked by: username_0 on 2019-12-15)

As some people have mentioned (eg. here), the only way to get the balance of an address in bitcoin core was to import it as a watch-only address and rescan the blockchain. Starting with bitcoin core v0.17, we can use the scantxoutset command, however this is quite slow:
> time bitcoin-cli scantxoutset "start" "[\"addr(17Pu3CEx34YX8bpGATq45PfL2fGBCPcr2u)\"]"
{
  "success": true,
  "searched_items": 64162818,
  "unspents": [
    {
      "txid": "9796cee98fa88efcb9fdb954188d276b73d6e76719af6b5470ad23a2f744ecca",
      "vout": 1,
      "scriptPubKey": "76a91446255848182640edff4d178f365d7824513bc28d88ac",
      "desc": "addr(17Pu3CEx34YX8bpGATq45PfL2fGBCPcr2u)#x2q6xgrk",
      "amount": 0.02155141,
      "height": 607852
    }
  ],
  "total_amount": 0.02155141
}

real    0m42.419s
user    0m0.007s
sys 0m0.003s 

42 seconds is quite slow, I would like to get something comparable to block explorers (less than 2 seconds). Is it possible to achieve faster results with some advanced bitcoin core configuration?
Or, is there any open-source project I could use to index the UTXO set by address? Not sure if libbitcoin, bitcoinj, bitcoinJS, etc. are able to do this faster. Some tool block explorers might use to provide this service would be what I am looking for.

**Tags:** bitcoin-core, address, utxo, utxo-set, blockchain-explorer


---

## 1 answers

### Answer by username_1 on 2019-12-15. Score: 3 | Accepted answer

There is no way to enable faster querying for arbitrary addresses than `scantxoutset` in bitcoind.

Explorers provide this functionality by maintaining a separate database of all addresses and transactions which is optimized for that kind of query. Bitcoin Core, on the other hand, is optimized for consensus related queries, which are largely a hashset lookup for a given input for a transaction.

You could try running something such as [ElectrumX](https://github.com/kyuupichan/electrumx), which backs the electrum wallet, or [Bitcore](https://github.com/bitpay/bitcore), which backs many of Bitpay's wallet and explorer services.

> **Comments:**
> **username_0**: Thanks. Any chance of bitcore or electrumX using bitcoin core's data folder to avoid storing ~300 GB twice?  
> **username_1**: You can read the data from an existing installation, but any indexing program will have to duplicate it into its own database to actually be able to efficiently answer your queries.  
> **username_0**: Yes, I read eletrumX's DB has ~30GB and can (and should) read the data from a bitcoin core full node. Checking now whether this is also de case for bitcore.  
> **username_1**: These are all solutions that operate on top of bitcoind, as that is still the source of truth - they simply add some indexing capabilities that extend the kind of queries you can perform. Your space usage will not really double, as bitcoind's stoage format is somewhat inefficient in favour of fast lookups for specific tx outputs. Traditional databases will do a more efficient job in a lot of cases  
> **username_2**: Hi @username_0 Were you able to get this to work? I'm curious to know since I'm looking to do something similar.  
> **username_2**: @RaghavSood "maintaining a separate database of all addresses and transactions"....how can I go about creating such a db myself?  
> **username_0**: @username_2 no fast and easy way to do it with only bitcoin core, you need to run an electrum server.  

---

