3

I am trying to restore my Bitcoin Core wallet, but I only have the private key and passphrase, I don't have a wallet.dat file.

I tried using

importprivkey privatekey xxxxxxxxxxxxxxxxxxxx

which gave me the error Rescan is disabled when blocks are pruned (code -4).

How can I import the key?

3 Answers 3

3

Generally, the wallet shipped with Bitcoin Core only keeps copies of any transactions that directly involve the wallet. When you import a key, your node scans the entire blockchain to see if any transactions involved that key.

A pruned node has processed the whole blockchain, but only keeps the tail end of the data. This means that when you import a private key in a pruned node, the pruned node does not have the data to check for relevant transactions. That's why it is incompatible with the rescan requirement. To find the transactions related to the key, you will need to repeat the initial synchronization of the blockchain.

As Prayank already stated in his answer, you could use

importprivkey "<key>" "" false

to import one or multiple private keys. The "false" in the third argument skips the usual rescan triggered by the import. This should avoid the error you are seeing.

After you have imported all relevant keys, you restart your node with the -reindex commandline option to start over with the initial sync. Your wallet will scan for relevant transactions during the synchronization and rediscover the funds and transaction history of the wallet.

If you wish to avoid performing another synchronization with your node, you could instead import the key into a light-client such as Electrum as suggested by RedGrittyBrick in another answer.

3
  • Should "getbalance" work before the full reindex is complete? For example, if my imported private key received Bitcoin in 2010 and Bitcoin Core has finished reindexing up to 2011, should gebalance show the balance as of 2011? This seems reasonable, but it's not the behavior I'm seeing and I'd like to avoid a long reindex to find out the import didn't work as expected.
    – Rich Remer
    Aug 23, 2021 at 20:53
  • Hi Rich, I asked here for you: bitcoin.stackexchange.com/q/108258/5406
    – Murch
    Aug 23, 2021 at 21:06
  • @RichRemer Ah, I realize that you are an experienced user from another site. You're asking a good question, please create a new topic. You can use the text of your comment verbatim for the question.--I've deleted the question I created, assuming that you will post one.
    – Murch
    Aug 23, 2021 at 21:08
0

I think your choices are

  • Restart your Bitcore-core node with adequate diskspace and pruning mode disabled, wait for it to sync all over again and then use importprivkey or
  • Import or sweep your private key into a different wallet such as Electrum. Optionally transfer the money back to your Bitcoin-core wallet. This might be quicker but you won't get the full transaction history back into Bitcoin-core
2
  • Thanks for the response, I restared but I am not sure how to disable the pruning.
    – Rohan
    Oct 28, 2020 at 1:41
  • Check the configuration file Oct 28, 2020 at 9:59
0

You can use the below format for importprivkey:

importprivkey "mykey" "" false

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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