How to import private keys
When using Cold storage, Paper wallet or Vanity Bitcoin Address you need to import Private keys. Since Bitcoin 0.6.0, you can import Private keys using build-in RPC command importprivkey. Before Bitcoin 0.6.0, you need to rely on third-party wallet.dat manipulation tool such as Pywallet.
As of August 2012, possibly the easiest way to import a private key is using Blockchain.info. Import can be done through the "Import/Export" screen, and when successful, bitcoins can be immediately sent to a new address outside Blockchain.info without needing to wait for any confirmations. The MtGox Bitcoin exchange will allow individual private keys to be redeemed with a wait time of 6 confirmations. There is an API method to import an entire wallet.dat as well.
This article describes how to import a private key through the RPC API of bitcoind, which is a topic for advanced users.
Start Bitcoin client
Unlike third-party wallet.dat manipulation tools such as Pywallet, you do not have to close the Bitcoin client before proceeding. Instead, you need to start the bitcoind server.
- Close bitcoin-qt and start bitcoind -damon in Terminal Emulator. The version of bitcoind MUST be the same as bitcoin-qt!
Bitcoin-QT does not enable its RPC interface by default. To enable it:
- Close Bitcoin-QT and restart it with bitcoin-qt -server.
Unlock your wallet
If you have an encrypted wallet (recommended), you need to unlock it temporarily before importing private keys. The RPC command for unlocking an encrypted wallet is walletpassphrase <passphrase> <timeout>. Typing this directly in a bash terminal will leave your wallet passphrase directly in the bash history but there is a trick. Simply add a space before the command:
(space)bitcoind walletpassphrase yourpassphrase 120
Another alternative is to use a bash variable:
read x (input you passphrase) bitcoind walletpassphrase "$x" 120 # Do not set the timeout too long or too short.
Import Private key(s)
The last command unlocked your wallet temporarily for 120 seconds, during which time you must import your private keys. Since private keys can be as important as your passphrase, you may want to use the same techniques as above to prevent their being recorded in bash history (bash variable or space before the command):
(space)bitcoind importprivkey "5yourveryveryveryverylongprivatekeystring" "my-new-key" # "my-new-key" is a label for the key/address pair and is optional
The importing process is now started. Bitcoind will rescan the entire block data to ensure this key has not been used before. This process will take from one to two minutes, depending on your CPU performance. DO NOT abort it before finishing!
If no errors occurs, the import is a success and Bitcoin-QT users will be able to see the new address in the GUI immediately. If you need to import more keys, just repeat the instructions above. There is currently no command to import a batch of private keys so you will need to wait a minute or two for each key to be imported.
This will lock your wallet again (so you don't have to wait for timeout)
unset x unset y
These commands will clear the passphrase and private key from memory if you used the read technique. If you started bitcoind, you will need to stop it before Bitcoin-QT will start again:
At some point, you may wish to delete private keys from a wallet.dat file but as of version v0.6 of Bitcoin-QT/bitcoind, there is no RPC method available for this purpose. To delete the keys please see Pywallet.