I might be over thinking this, but I'm trying to figure out the best way to build an unspent output pool. Should I just naively parse every block? Every input gets removed from the hash set, and every output gets added back in? Seems terribly inefficient. The thing is it doesn't seem like there is anyway to accurately build this utxo pool without traversing the block chain at least once and constructing it. Is there a well defined short-cut I should be aware of? Pointers welcome.

I guess I can iterate through the on-disk blocks first, and then update as blocks come in.

  • That doesn't sound inefficient at all. What seems inefficient about it to you? Jun 3 '14 at 5:15
  • I think I was just thinking that there might be a more efficient way. I thought the official client stored the utxo pool in some kind of tree structure, just trying to get more insight into this.
    – Matt
    Jun 3 '14 at 14:42
  • You can just use RPC to get the unspent outputs pool straight from bitcoind.
    – user13413
    Jun 3 '14 at 21:06
  • @goatse Which command?
    – T9b
    Jul 21 '14 at 22:20

There is already a pool with the information that you are willing to build: the UTXO set. You can access it by querying the LevelDB located in .bitcoin/chainstate of a full node.

However, there is no easy way of doing so by using RPC commands, you should extract the information by yourself.

I can provide a way to do so if you needed, and an extensive explanation of what are you going to find in each entry of the LevelDB.

  • chainstate is only the index of full chain Apr 14 '17 at 1:38
  • In the chainstate you can find all the data you may need to know about the UTXOs, such as the id, out index, amount, scriptPubKey, block in which it has been included, and whether it is coinbase or not.
    – sr-gi
    Apr 14 '17 at 13:36
  • So could you tell about '*.ldb' file format? Apr 14 '17 at 13:49
  • 1
    Sure, you can check this answer: bitcoin.stackexchange.com/a/52167/30668
    – sr-gi
    Apr 14 '17 at 16:05

You can directly get UTXO set from bitcoind using listunspent RPC call.

  • 4
    Only for UTXOs that are yours (or otherwise contribute to your own wallet's balance). Jan 9 '18 at 9:00

There is no simple way to get what you want except that way you try to describe.

RPC did not support any command of what you want.

If you need UTXOs, you must disassemble every *.dat binary file in series from the first and keep each output for checking on spending in future.

  • Sorry but not true, what @Matt is willing to build is already part of the Bitcoin core client, he just need to check the UTXO set. It is indeed no easy to access, since there is no RPC command available, so he would need to access the LevelDB stores in /chainstate and most likely code his own parser. However, it is way easier than disassembling every .dat file and checking when every UTXO has been spend over the years.
    – sr-gi
    Apr 12 '17 at 9:26
  • @sr-gi I made it without of any client. UTXO database from raw dat files. Jun 2 '18 at 3:34

The following worked for me on a Bash command window:

curl https://blockchain.info/unspent?active=place_bitcoin_address_here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.