1

I have a ton of old backed up wallet.dat files with zero BTC in them, but (probably) the records of my old Bitcoin transactions in them, which I'm trying to extract as CSV data.

I already looked at the command line options and found no instance of "extract" or "CSV", but is there some way to do something simple on the command line such as:

bitcoincore.exe --extract-csv-transactions-from-wallet=wallet1.dat -o wallet1.csv
bitcoincore.exe --extract-csv-transactions-from-wallet=wallet2.dat -o wallet2.csv
bitcoincore.exe --extract-csv-transactions-from-wallet=wallet3.dat -o wallet3.csv
...

?

My current method of manually loading four of them in at a time, manually adding them to the config file and starting Bitcoin Core, is a nightmare. It has been saying "Rescanning" for an hour now with no sign of it ever stopping and that's just for the first batch of four wallets... out of tons.

This is going to be a multi-weeker nightmare project, isn't it?

  • I would instead look at other utilities or libraries such as btcutils or pywallet. – RedGrittyBrick Oct 06 '21 at 10:00
  • 1
    Does this answer your question? Dumping private keys from wallet.dat from command line (pywallet.py alternatives) (note the answers cover dumping all wallet data, not just keys) – RedGrittyBrick Oct 06 '21 at 10:02
  • @RedGrittyBrick I don't trust anything but Bitcoin Core. And I'm not trying to dump any private keys. – Matoshi Sakabloto Oct 06 '21 at 10:03
  • Why does it have to "Rescan"? Can't this be skipped? – Matoshi Sakabloto Oct 06 '21 at 10:08
  • From elsewhere: 'The wallet file stores up to which block it has "seen" the chain. At startup, an automatic rescan happens for exactly the missing part.' I guess this is because the prime purpose of Bitcoin core is to function as a wallet, not to export CSV data from multiple wallet.dat files. It is presumably optimised for the former task, not the latter. – RedGrittyBrick Oct 06 '21 at 10:15
  • You can load wallets without restarting Bitcoin Core by using the loadwallet and unloadwallet RPCs. You can use the listtransactions RPC to get all of the transactions in JSON form and convert that into whatever format you want. – Ava Chow Oct 06 '21 at 18:41
  • Rescan is required in order for the wallets to have gotten any transactions that were made during the time the wallet was offline. A workaround to avoid that is to remove all blockchain data and then start Bitcoin Core with -connect=0. This will force it to not make any network connections so that it doesn't sync the blockchain, and hence any loaded wallets will not have anything to rescan. However this may miss some transactions, and some functionality may be disabled as it will not be synced. – Ava Chow Oct 06 '21 at 18:43
  • Some reviewers supposed that this is a duplicate of a question about getting the private keys, but that is not the asker's goal. @AndrewChow provided good and helpful answers which the asker could work into a helpful answer to his own question. I vote to keep it open in the hope that one of them will do that. – Dave Scotese Oct 09 '21 at 00:52

1 Answers1

2

There is no way to export all of the transactions to a csv. However you can get the transaction in JSON using the listtransactions RPC.

Bitcoin Core will always rescan when a wallet is loaded because it must be sure that it has seen all of the wallet's transactions so that the user does not appear to have lost any funds. For old wallets, it ends up having to rescan a significant portion of the blockchain. There is no way to disable this behavior.

However, if you are sure that no rescan is necessary, it is possible to force Bitcoin Core to not have any blockchain data so that the rescan completes quickly and does not do anything. You can do this by removing all blockchain data from the datadir and starting Bitcoin Core with -connect=0. This will force Bitcoin Core to not connect to the network so it will not be able to download the blockchain. Additionally, because you have removed any previous blockchain data, Bitcoin Core will be reset to the genesis block as the only block in the blockchain. Loading a wallet at this point will result in no rescan.

Lastly, to speed things up, instead of constantly stopping and starting Bitcoin Core to load new wallets, you can use the loadwallet RPC to load a wallet, and unloadwallet to unload the wallet when you are done with it.

Some python-like pseudocode that shows what this would look like:

for wallet in wallets:
    rpc.loadwallet(wallet)
    print(rpc.listtransactions())
    rpc.unloadwallet(wallet)
Ava Chow
  • 70,382
  • 5
  • 81
  • 161