How to find all UTXOs?

4

1

It is known, that UTXOs stored in chainstate database.

But how to get them in simple txt view? Not ballances, but each UTXO.

D L

Posted 2019-01-10T04:18:28.877

Reputation: 478

Answers

5

With vanilla Bitcoin Core, there is no efficient way to do this.

I see two options:

a) Slow and very inefficient RPC loop (not recommended)

  1. Get the genesis block hash (RPC getblockhash 0)
  2. Get the block with all transaction (RPC getblock <hash> 2, 2 stands for verbosity with transaction)
  3. Loop through all transactions and all its outputs, call gettxout <txid> <n> (where n is the outputs index)
  4. If gettxout returns an object, the output is unspent (UTXO), dump it to a text file

This may take a couple of hours or days (depending on your machine).

b) Fast way by patching Core (0.17.1)

  1. Change the code of the function call GetUTXOStats(), apply a text file dump in the utxo set loop (while (pcursor->Valid()) {)
  2. Compile
  3. Call RPC gettxoutsetinfo and let your added code dump data per UTXO to a file (or similar)

Jonas Schnelli

Posted 2019-01-10T04:18:28.877

Reputation: 5 465