13

I have a private key and I want to add it to the keys in the Bitcoin client. Is there an easy way to do this?

7

Importing could be done with Pywallet or hopefully soon-to-be-official wallet export/import bitcoin patch, but make sure to backup your wallet first.

  • Pywallet doesn't work on Mac. When the patch is official, will it be a part of the normal version of the client? – shoeless joe Dec 17 '11 at 19:15
  • @shoeless joe, that is wrong because "Pywallet is a python script that deals with wallets and keys" and "Confirmed to work on: Ubuntu 32bit(me), Windows 32bit(me) 64bit(ctoon6), OSX(defxor)" , as for the patch, I think you better ask Gavin – Serith Dec 17 '11 at 19:42
  • What I mean is that it doesn't work on Mac unless you load a thousand non-native programs: bitcointalk.org/index.php?topic=34028.msg437850#msg437850 – shoeless joe Dec 18 '11 at 8:46
  • Quite disappointing: seems you have to import keys one by one? – o0'. Apr 30 '12 at 14:23
  • The answer was written a while ago, a lot has changed since then, and I remember some buzz about the functionality on forum. Maybe someone made an improvement, my first guess would be to look at Armory client: bitcoinarmory.com – Serith May 4 '12 at 1:09
4

An answer to How can I export the private key for an address from the satoshi client? gives the steps required to export a private key. The steps to import a private key are the same except that you need to change "dumpprivkey 1aaabbb..." to "importprivkey 5aaabbb...".

If you use bitaddress.org's "Bulk Wallet" feature you can generate a list of private keys, like this:

1,"1AWUTMBC3XuTnPugwznNoju37ptACYRJyn","5K4dStGTDUR4r9yCwe7DqLunr5o7fjs2rH1Qb7KQg76d6KASGqv"
2,"1QKvh1wy8Vgri7BCGnY3XiXsdoX8SpzYTK","5JT6RJLjkKp5UDkkBsTNjNFgoo8o3bB3qK1qvsxKawCjh8X4pQQ"
3,"171er29jxgoUw5GNZFRF5w7FCUeXvPHbyK","5KBmhDfAEPDTd9asLCYcWaJNkc9KNvBmFoZzPTWfCdq3CaLePAB"

To import all the private keys into your wallet:

  1. copy/paste the list into a temporary file, /tmp/bitaddress.txt making sure there's a newline on the end of the last line
  2. tr -d '"' < /tmp/bitaddress.txt | tr , ' ' | while read number address privkey; do echo importing $address; bitcoind importprivkey $privkey; done

Note: if you're running Windows you'll need to modify the command in step 2 to whatever the equivalent Windows shell command would be.

Note 2: the importprivkey command is very slow since it rescans the whole transaction history after each private key import. It's possible to speed it up considerably by commenting out two lines in the bitcoind source code.

Note 3: importprivkey now has an optional rescan option which you can set to false. This will make importing much faster, and you don't have to edit the source code.

  • Hi Chris, this is a very good answer, but it presupposes that bitcoind is running on my computer, which it is not. So how do I get bitcoind running so I can give it the importaprivkey command? – shoeless joe Aug 6 '12 at 17:07
  • You don't need the bitcoind server running. The regular bitcoin-qt program will act as a server if you start it with the -server argument. You will need the bitcoind program to act as the client though. Do you have a copy of the bitcoind program? I thought it came with bitcoin-qt, but maybe that's not true. – Chris Moore Aug 6 '12 at 22:18
  • Yes, I have the bitcoin-qt program. I could start it in a Terminal window using -server argument. I can't find bitcoind on the bitcoin.org website and it is not in the bundle for MacOS. – shoeless joe Aug 7 '12 at 20:51
  • See bitcoin.stackexchange.com/a/4251/659 - it appears that you will need to build bitcoind from source. – Chris Moore Aug 8 '12 at 0:38
  • So the whole thing falls apart again and I am left doing really hacky things with lots of programs and libraries. – shoeless joe Aug 10 '12 at 3:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.