Comment
Author: Admin | 2025-04-27
Bitcoin UTXO DumpWarning: This tool may corrupt your chainstate database. If it does, you will need to run bitcoind -reindex-chainstate the next time you run bitcoin, and this usually takes around a day to complete. It's not a terrible problem, but it can be annoying. I'm not entirely sure why it happens, so if you can figure out how to fix it, that would be cool.You can get around this issue by first copying the chainstate database to an alternate location and then run bitcoin-utxo-dump pointing to this alternate location. Here's a example:# 0. stop bitcoin daemonbitcoin-cli stop# 1. copy the chaninstate data to an alternative locationrsync --delete -av ~/.bitcoin/chainstate/ ~/bitcoin-chainstate-clone/# 2. now run the bitcoin-utxo-dump pointing to this alternate locationbitcoin-utxo-dump -db ~/bitcoin-chainstate-clone/Get a list of every unspent bitcoin in the blockchain.The program iterates over each entry in Bitcoin Core's chainstate LevelDB database. It decompresses and decodes the data, and produces a human-readable text dump of all the UTXOs (unspent transaction outputs).Example CSV Results:count,txid,vout,amount,type,address1,033e83e3204b0cc28724e147f6fd140529b2537249f9c61c9de9972750030000,0,65279,p2pkh,1KaPHfvVWNZADup3Yc26SfVdkTDvvHySVX2,e1c9467a885a156e56a29d9c854e65674d581ad75611b02290454b4862060000,1,9466355,p2pkh,1LpCmEejWLNfZigApMPwUY9nZTS8NTJCNS3,a1f28c43f1f3d4821d0db42707737ea90616613099234f905dfc6ae2b4060000,1,339500,p2pkh,1FuphZ7xVPGrxthQT1S8X7nNQNByYxAT3V4,818f5b9e3ede69da765d4c24684e813057c9b1f059e098661369b0a2ee060000,0,300000,p2pkh,18Y9yhjU9g2jjJmvaUy7TmUNZH9iPzQ4dd5,d2f5e439152d076593a145581f8d76ea2e48ed155285b9a245cd42dd06070000,0,100000,p2pkh,1EKHTvovYWHfUJ6i9vsoidyTPQauCPH1qC6,ea0c69fbd2389556b01771948ffc0507cf303bdc5a1b91b31acf9ecf6a070000,1,27668,p2pkh,1fkEhLpPKdmKtaxKdp4yDp1c87dF7GDub7,05eafead65250a24b1592f8a006cbeab16a7b17ed2616507c5e0bd67bd070000,1,32000,p2pkh,15KmfJcGNfL29vpsSJ37uPzTQfr8Qe17Gq8,2c0c985d384160d8c50c438bc67e639fe6047a7f2bac00a1238ca6a6d3070000,0,41936,p2pkh,17up1oPxBMTfZdehzy4v81KzLRHGDNX8ff9,8261170b7ae26be70bd9e8f0e4bf19ce3571bb6464cdf9e478c471d372080000,1,4528208,p2pkh,1P6Ae7unrSjtx9J5SjWuwAdZBoWcbcjzBZ...InstallFirst of all, you need to have a full copy of the blockchain. You also need to install LevelDB:sudo apt install bitcoindsudo apt install libleveldb-devAfter that, if you have Go installed you can do:go install github.com/in3rsha/bitcoin-utxo-dump@latestThis will create a binary called bitcoin-utxo-dump, which you can call from the command line:This will start dumping all of the UTXO database to a file called utxodump.csv.NOTE: This program reads the chainstate LevelDB database created by bitcoind, so you will need to download and sync bitcoind for this script to work. In other words, this script reads your own local copy of the blockchain.NOTE: LevelDB wasn't designed to be accessed by multiple programs at the same time, so make sure bitcoind isn't running before you start (bitcoin-cli stop should do it).UsageThe basic command is:You can view the results in the terminal with the -v (verbose) flag (but this will make the script run about 3 times slower):The results will be written to the file in the current directory called utxodump.csv. You can choose your own filename with the -o option:$ bitcoin-utxo-dump -o ~/Desktop/utxodump.txtIf you know that the chainstate LevelDB folder is in a different location to the default (e.g. you want to get a UTXO dump of the Testnet blockchain), use the -db option:$ bitcoin-utxo-dump -db ~/.bitcoin/testnet3/chainstate/By default this script does not convert the public keys inside P2PK locking scripts to addresses (because technically they do not have an address). However, sometimes it may be useful to get addresses for them anyway for use with other APIs, so the following option allows you to return the "address" for UTXOs with P2PK locking scripts:$ bitcoin-utxo-dump -p2pkaddressesYou can select what data the script outputs from the chainstate database with the -f (fields) option.
Add Comment