I managed to recover a Bitcoin Core wallet from a wallet.dat file that has some funds in it. I did this on an old offline PC running Windows Vista, using Bitcoin Core version 16.3. Now, I really need to check if the wallet.dat file is good, but I don't want to make any transactions just yet. I can unlock and access the wallet without syncing, and it shows the same balances as I see on the explorer. Can I completely trust that those balances are spendable? Let's say, for instance, some transactions happened after the wallet was backed up and encrypted would it still open and display those balances? Is there anything I should do to ensure those balances are secure? Or is it safe since the wallet shows the same transactions and balances as the explorer after I unlock it?
I think you should be able to verify the integrity of a wallet.dat file without making a transaction. You could possibly try bitcoin-cl. try opening your Bitcoin Core wallet offline then try using bitcoin-cli command-line tool to verify balance.
Then replace <wallet_data_dir> with the directory containing your wallet.dat file.
Or you can download pywallet from git hub and try running;
Like I said earlier also try replacing <wallet_dat_file>` with the path to your wallet.dat file
Make sure to run everything offline to be on a safer side. Also, if any transactions were made after the wallet backup, the wallet would still show the old balances. To verify recent transactions, you need to resync the wallet or check online explorers.
If you are able to unlock your wallet and all of the transactions and balances show as you expect, then you can be reasonably confident that you can spend that balance.
The wallet will perform its own integrity check when unlocking - it either computes the public key from the stored private key and compares it against the stored public key, or it does that for a single key and checks that the rest had a valid stored checksum. This should protect against random corruption, although the latter does not protect against malicious modification (not a problem if the wallet is actually yours).
The balance is computed on-the-fly by checking which outputs of the transactions stored in the wallet are spendable by the stored keys (or descriptors), so as long as the keys are correct, the balance should be spendable.
Thanks for your suggestions. I tried the datadir=<wallet_data_dir> getbalance command, but "method was not found (code -32601)". Perhaps the getbalance feature was not yet implemented when version 16.3 was released. I'll still have to look into your second suggestion.
I noticed an error in my post: The wallet shows 0 balance, as expected, but does show the transactions. The wallet.dat file has been rescanned by a synchronized v 19.01 quite recently though, and then it showed the balance in correspondence with the transactions.
Thanks. I hope it's as simple as that. I noticed an error in my post: The wallet shows 0 balance, as expected (never synchronized), but it does show the transactions. The wallet.dat file has been rescanned by a synchronized v 19.01 quite recently though, and then it showed the balance in correspondence with the transactions.
What made me worry though, is that when I tested the encryption/unlocking procedure using the command line, with the empty wallet.dat file that came with the intallation, then a message warned me, that a new back-up should be made after each outgoing transaction. I made some back-ups in between several transactions. And these indeed do not seem to work at all. They try to run the client, then it shuts down. I might have used the back-up button that put the whole bitcoin wallet on the USB sticks back then. I don't remember. Perhaps I messed that up in another way. No wallet.dat files to be found there either. Luckily, I still had access to the original wallet.dat file, so I could just rescan. I'm worried, because I can't be completely sure if any of the transactions were made after I copied the encrypted wallet.dat file. But if you can mess the back-up as easiiy as that, then there are probably many more ways, that you can mess things up. So as of now, things look pretty fine, but I'm still worried what will happen if I want to transact from the wallet.
Mod note: consecutive posts merged
Which pywallet fork you use? I just re-checked https://github.com/jackjack-jj/pywallet, but the source code doesn't mention anything about command check-integrity.
That makes sense, unless the wallet.dat file changes after each transaction. I might repeat the experiment later today to check what the warning message that worried me to see was actually about.
After encryption of the wallet, the following message popped-up:
IMPORTANT: Any previous backups you have made of your wallet file should be replaced with the newly generated, encrypted wallet file. For security reasons, previous backups of the unencrypted wallet file will become useless as soon as you start using the new, encrypted wallet.
As mentioned, I had made backups of the wallet (which included the .exe file) on several USB sticks. I remember, that Bitcoin core once would start right from the USB sticks. On second inspection, they do start Bitcoin Core, without any errors, but no transactions are shown, and no block source is available. These backups were not encrypted. If the warning message is correct, then the unencrypted wallet would not work, but I am not going to verify that. In this case, the security feature might have protected me, because I did use the wallet after encryption. But if I would not have had access to the encrypted wallet.dat file, then I would effectively have spoiled the balances.
Can I conclude, that the balances on the wallet.dat file that I encrypted, and never changed passwords, shoud be spendable?
As this was unknown to me, I am still wondering if there might be more pitfalls that could render the wallet useless, even though everything seems fine, without putting it to the test by making a transaction?
There is no such message. The message about backups, which you have already seen, is that you need to create a backup after encrypting. There is no need to make a backup after every transaction, nor really with any frequency.
The reason to create a backup after encrypting is because encrypting will generate an entirely new set of keys that will be used going forwards. The old keys remain in the wallet, they just are not used for any new addresses since they were unencrypted and therefore potentially exposed. If you did not make a new backup, any previous backups of the unencrypted wallet would not contain the newly generated keys and therefore restoring such backups would result in missing funds.
Generally, no, as long as you read all of the instructions presented and any dialogs or warning messages. We're pretty thorough about considering what could go wrong and either protecting against those issues or letting the user know.
I should have been more carefull in my post mentioning the warning message. Hopefully the inaccuracy is now properly corrected. I once checked the passphrase for a copy of the encrypted wallet.dat file by "changing" the passphrase with the same passphrase. I can't remember any warning messages after I did that. I'm wondering if a new set of addresses is generated only when the wallet is first encrypted or if this process repeated everytime you change the passphrase?
I am curious though. If you had unencrypted backups of the wallet before, but then before you send any transactions or receive coins to any new addresses, you destroy the wallet.dat file and import it again (or just import it to another computer with Bitcoin Core on it), restoration from the unencrypted backup would technically work, right? As there are no UTXOs associated with any new keys.
That specific scenario will work because as explained by achow101, wallet encryption doesn't get rid of the old used keys.
Not entirely related to the question but will affect the result nonetheless:
In a scenario when it's an old not-synced non-HD wallet.dat backup, it depends on the wallet's keypool and the number of used keys after the backup.
Not much of a problem with newer non-HD wallet.dat with 1000-key gap limit unless it's used a lot.
Do you double-check what you write? bitcoin-cli getbalance might show outdated balance if you don't let Bitcoin Core sync the wallet (a.k.a. finding relevant transaction associated with the wallet). And FWIW, default parameter for verifychain (at least on Bitcoin Core 28.0) doesn't verify whole blockchain.