Posts Tagged ‘python

From time to time people tend to remember that they have minded BTC, LTC, DOGE or another of the earlier cryptocoins back in the day when they suddenly find an old wallet.dat file and then the problem with recovering the private keys and the coins in the wallet arises, we often get questions on how to do that. The easiest way would of course be to just copy the wallet.dat file in a new installation of Bitcoin Core or the respective local wallet and wait for the blockchain to sync in order to have access to any coins stored in the wallet. Int he case of Bitcoin however this is a slow process requiring you to download 150 GB of data (the whole blockchain), so alternative ways are being looked into and there are some that can be easier. One such way is to use the PyWallet Bitcoin wallet importer/exporter Python script that has been available for ages and that works great for giving you all your public and private keys from a wallet.dat file.

PyWallet however is a Python script that does require you to have Python installed and it requires an older version 2.7, so it will not work with the latest 3.x releases as there are changes that will prevent you from running the script. We are going to go through a short guide on how you can export your public/private keys from a wallet.dat under Windows here, the procedure for Linux is very similar as well. So you need to download and install Python 2.7 first, this is a Windows package of Python, there are no other dependencies to run the script under Windows. Then you need to install it in an easy folder like C:\Python27 for example, copy the pywallet.py script and the wallet.dat files in the same folder and then run the following command:

python pywallet.py --dumpwallet --datadir=.

If you have used the wallet for mining you may have more than just a few addresses inside, so you can use the below code to save the output into a wallet.txt file for easy use instead of just outputting it in the console window:

python pywallet.py --dumpwallet --datadir=. > wallet.txt

Just open up the text file and you will see a list of exported public keys (addresses) and private keys that were inside the wallet.dat wallet file. If you had the wallet encrypted you will also need to provide the password you used fr the encryption in order fro the data to be decrypted first. If you do not remember that password you have used to encrypt the wallet.dat file, well that would be a serious problem as recovering any coins inside the wallet has just become much harder that you though it could be.

You can use any block explorer for the respective coin to check if it has any balance inside by pasting your address (public key), so that you can be sure if there are coins or not in an address. If there are you can then just import the public/private key in a new wallet and then do whatever you want with the coins inside. Importing the key pair can vary depending on the wallet you choose to use, so check what is the procedure and make sure that you can import a wallet using the public and private key(s) you have just obtained using the PyWallet script.

There is also a more up to date fork of PyWallet available as well that offers some useful additional features, so you may also check it out if the original one does not do what you want it to, although the original one is perfectly fine for recovering the keys.


top