How to import private keys: Difference between revisions

From Bitcoin Wiki
Jump to navigation Jump to search
Casascius (talk | contribs)
No edit summary
Tkalfigo (talk | contribs)
 
(26 intermediate revisions by 13 users not shown)
Line 1: Line 1:
{{Stub}}
'''WARNING'''
 
Before reading this page, users should note that messing with ECDSA private keys is very dangerous and can result in losing bitcoins, even long after the import.
It is recommended that outside of self-generated vanity addresses, users should ''never'' import (or export) private keys.<ref>[https://bitcoin.stackexchange.com/questions/29948/why-doc-says-importing-private-keys-is-so-dangerous Bitcoin StackExchange - Why doc says importing private keys is so dangerous?]</ref><ref>[https://bitcoin.stackexchange.com/questions/18619/why-so-many-warnings-about-importing-private-keys Bitcoin StackExchange - Why so many warnings about importing private keys?]</ref>
 
= Using Blockchain.info =
As of August 2012, possibly the easiest way to import a private key is using [[Blockchain.info]]'s My Wallet service. When successully imported through the "Import/Export" screen, the bitcoins assigned to a private key can be immediately sent to any Bitcoin address. '''It is extremely risky and not recommended to use Blockchain.info or any online third-party service to import private keys, because they can steal your BitCoins if they have the keys. It's best to import them using bitcoind as described below.'''
 
= Using BIPS =
As of August 2013, [[File:BIPS.gif|20px|link=https://bips.me]] [[BIPS]] allows for easy import of private key using Paper Wallet - Import. User can choose to type in the private key manually or scan a QR code containing the private key using the camera. The user must wait 6 confirmations for access to the funds, and system is based on batch importation. '''It is extremely risky and not recommended to use BIPS or any online third-party service to import private keys, because they can steal your BitCoins if they have the keys. It's best to import them using bitcoind as described below.'''
 
= Using Mycelium =
Steps described are with the following settings:
* Export mode enabled
* Aggregated view disabled
 
== Partial spend from cold storage ==
Use this function if you would like to keep some funds on the paper wallet.
# Download [https://play.google.com/store/apps/details?id=com.mycelium.wallet&hl=en Mycelium] from the Android Play Store or through iTunes.
# Press the menu button and select "Cold Storage"
# Scan in private key
# Select your destination address
# Select the amount
## Press the blue currency tag at the top to toggle currency.
# Send!
 
After spending, the private key in memory is destroyed so the paper private key remains somewhat secure. Despite this, best practice is to immediately send the remaining balance to a paper wallet that was generated offline.
 
== Import key from a paper wallet ==
Use this function if you would like to import a private key so all funds are immediately available for spending.
# Download [https://play.google.com/store/apps/details?id=com.mycelium.wallet&hl=en Mycelium] from the Android Play Store or through iTunes.
# Key Management
# Press the blue '+' symbol
# Scan in private key
 
After importing this paper private key, you might consider destroying the original so it cannot be found and your funds stolen. Alternatively, you can keep it safe to be used as an offline backup.
 
= Using bitcoind =
'''If you have Version 7 or later it is now trival.''' See: [[How to import private keys v7+]]
 
If you are using [[Cold storage]], a [[Paper wallet]] or generating [https://bitcointalk.org/index.php?topic=25804.0 vanity addresses] you may have a need to import a [[Private key]]. Since Bitcoin-QT/bitcoind v0.6.0, you can import private keys using built-in RPC command [[importprivkey]]. Before v0.6.0, you needed to rely on third-party [[wallet.dat]] manipulation tool such as [[Pywallet]].
 


When using [[Cold storage]], [[Paper wallet]] or [https://bitcointalk.org/index.php?topic=25804.0 Vanity Bitcoin Address] you need to import [[Private key]]s. Before Bitcoin 0.6.0, you need to rely on third-party [[wallet.dat]] manipulation tool such as [[pyWallet]]. Since Bitcoin 0.6.0, you can import Private keys using build-in RPC command [[importprivkey]]. Here are some instructions for desktop users (official bitcoin-qt client).


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.


This article describes how to import a private key through the RPC API of bitcoind, which is a topic for advanced users.
This article describes how to import a private key through the RPC API of bitcoind, which is a topic for advanced users.
'''Note that importing a key to bitcoind and/or Bitcoin-Qt may be dangerous and is not recommended unless you understand the full details of how it works'''


== Start Bitcoin client ==
== Start Bitcoin client ==
Unlike third-party wallet.dat manipulation tool such as [[pyWallet]], you do not have to close Bitcoin client before proceeding. In contrary, you need to start the bitcoind server.
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 <code>bitcoind -daemon</code> in Terminal Emulator. The version of bitcoind MUST be the same as bitcoin-qt!


Bitcoin-qt do not start with a bitcoind server by default so it cannot accept RPC commands by default. You can do one of this:
Bitcoin-QT does not enable its RPC interface by default. To enable it:
* Close bitcoin-qt and start ''bitcoind -damon'' in Terminal Emulator. The version of bitcoind MUST be the same as bitcoin-qt!
* Close Bitcoin-QT and restart it with ''bitcoin-qt -server''.
* Close bitcoin-qt and restart it with ''bitcoin-qt -server''. This will make bitcoin-qt accept RPC commands. You can use your client from both GUI and CLI now!


== Unlock your wallet ==
== Unlock your wallet ==
If you have an encrypted wallet (which is a good idea), you need to unlock it temporarily in memory before importing or exporting Private keys. The RPC commands for unlocking is ''walletpassphrase <passphrase> <timeout>''. But typing this directly in Terminal Emulator will leave your wallet passphrase directly in bash history. You can do this do prevent that:
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 are a couple of techniques you can use to avoid this. Simply add a space before the command:


  read x
(space)bitcoind walletpassphrase yourpassphrase 120
  (input you passphrase)
 
Another alternative is to use a bash variable:
 
  read -s -p 'Type your passphrase: ' x
  (input your passphrase)
  bitcoind walletpassphrase "$x" 120  # Do not set the timeout too long or too short.
  bitcoind walletpassphrase "$x" 120  # Do not set the timeout too long or too short.


By doing so, your passphrase will not be recorded into bash history. But be careful with people standing behind you since the passphrase are on your screen...
== 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


== Import Private key(s) ==
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!
The last command unlocked your wallet temporarily in memory for 120 seconds. You need to finish importing keys before timed out. Since Private keys are as important as your passphrase, you may want to use these commands to import them instead of typing / pasting them directly in Terminal Emulator to prevent their being recorded in bash history:


read y
To avoid rescanning run the following.
(type / paste your Private key)
bitcoind importprivkey "$y" "my-new-key"  # Label can be omitted


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 about one minute or two, depending on your CPU performance. DO NOT abort it before finishing!
(space)bitcoind importprivkey 5yourveryveryveryverylongprivatekeystring" "label-here" rescan=false


If no errors occurs, the import is a success. If you run your bitcoind via bitcoin-qt, you can see your new address in the GUI now. If you need to import more keys, just repeat the instructions above. Right now there are no ways to import keys in batch so you have to wait one minute or two for every key imported...
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.


== Cleaning up ==
== Cleaning up ==


  bitcoind walletlock
  bitcoind walletlock
This will lock your wallet again (so you don't have to wait for timeout)
  unset x
  unset x
  unset y
  unset y


This will lock your wallet again (so you don't have to wait for timeout) and clear the passphrase and Private key from memory. If you start bitcoind in the first way above, you also need to stop it, or bitcoin-qt cannot start again:
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:


  bitcoind stop
  bitcoind stop


Happy importing!
===Deleting Keys===
At some point, you may wish to delete private keys from a wallet.dat file but as of version v0.6.0 of Bitcoin-QT/bitcoind, there is no RPC method available for this purpose.
 
==References==
<references />
 
[[Category:Instructional]]

Latest revision as of 19:39, 19 August 2019

WARNING

Before reading this page, users should note that messing with ECDSA private keys is very dangerous and can result in losing bitcoins, even long after the import. It is recommended that outside of self-generated vanity addresses, users should never import (or export) private keys.[1][2]

Using Blockchain.info

As of August 2012, possibly the easiest way to import a private key is using Blockchain.info's My Wallet service. When successully imported through the "Import/Export" screen, the bitcoins assigned to a private key can be immediately sent to any Bitcoin address. It is extremely risky and not recommended to use Blockchain.info or any online third-party service to import private keys, because they can steal your BitCoins if they have the keys. It's best to import them using bitcoind as described below.

Using BIPS

As of August 2013, BIPS allows for easy import of private key using Paper Wallet - Import. User can choose to type in the private key manually or scan a QR code containing the private key using the camera. The user must wait 6 confirmations for access to the funds, and system is based on batch importation. It is extremely risky and not recommended to use BIPS or any online third-party service to import private keys, because they can steal your BitCoins if they have the keys. It's best to import them using bitcoind as described below.

Using Mycelium

Steps described are with the following settings:

  • Export mode enabled
  • Aggregated view disabled

Partial spend from cold storage

Use this function if you would like to keep some funds on the paper wallet.

  1. Download Mycelium from the Android Play Store or through iTunes.
  2. Press the menu button and select "Cold Storage"
  3. Scan in private key
  4. Select your destination address
  5. Select the amount
    1. Press the blue currency tag at the top to toggle currency.
  6. Send!

After spending, the private key in memory is destroyed so the paper private key remains somewhat secure. Despite this, best practice is to immediately send the remaining balance to a paper wallet that was generated offline.

Import key from a paper wallet

Use this function if you would like to import a private key so all funds are immediately available for spending.

  1. Download Mycelium from the Android Play Store or through iTunes.
  2. Key Management
  3. Press the blue '+' symbol
  4. Scan in private key

After importing this paper private key, you might consider destroying the original so it cannot be found and your funds stolen. Alternatively, you can keep it safe to be used as an offline backup.

Using bitcoind

If you have Version 7 or later it is now trival. See: How to import private keys v7+

If you are using Cold storage, a Paper wallet or generating vanity addresses you may have a need to import a Private key. Since Bitcoin-QT/bitcoind v0.6.0, you can import private keys using built-in RPC command importprivkey. Before v0.6.0, you needed to rely on third-party wallet.dat manipulation tool such as Pywallet.



This article describes how to import a private key through the RPC API of bitcoind, which is a topic for advanced users.

Note that importing a key to bitcoind and/or Bitcoin-Qt may be dangerous and is not recommended unless you understand the full details of how it works

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 -daemon 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 are a couple of techniques you can use to avoid this. Simply add a space before the command:

(space)bitcoind walletpassphrase yourpassphrase 120

Another alternative is to use a bash variable:

read -s -p 'Type your passphrase: ' x
(input your 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!

To avoid rescanning run the following.

(space)bitcoind importprivkey 5yourveryveryveryverylongprivatekeystring" "label-here" rescan=false

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.

Cleaning up

bitcoind walletlock

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:

bitcoind stop

Deleting Keys

At some point, you may wish to delete private keys from a wallet.dat file but as of version v0.6.0 of Bitcoin-QT/bitcoind, there is no RPC method available for this purpose.

References