wallet: importprivkey fails to import private key #21275

issue jarolrod opened this issue on February 23, 2021
  1. jarolrod commented at 8:09 AM on February 23, 2021: member

    As reported by @chaihahaha in https://github.com/bitcoin-core/gui/issues/218, importprivkey is failing to import a private key into a blank wallet.

    To Reproduce (steps with bitcoin-qt):

    • Have a private key, I obtained one with dumpprivkey
    • Create a new Encrypted wallet with Make Blank Wallet option selected. This option means that the wallet starts out with no private keys and you can add them in later with importprivkey or sethdseed
    • Go over to console and unlock wallet with walletpassphrase "123" 60
    • In console, run: importprivkey "priv_key" "label" false
    • Run getnewaddress -> get error: Error: This wallet has no available keys (code -4)

    Note: I was also able to reproduce using bitcoind and bitcoin-cli. Additionally, the debug log says I already have this key in pubkey and already have the script. This is similar to #16711. You can still populate the blank wallet with a private key using sethdseed.

    Running getwalletinfo shows that, in fact, the private key was not added:

    {
      "walletname": "new-wallet",
      "walletversion": 169900,
      "format": "bdb",
      "balance": 0.00000000,
      "unconfirmed_balance": 0.00000000,
      "immature_balance": 0.00000000,
      "txcount": 0,
      "keypoololdest": 1614066198,
      "keypoolsize": 0,
      "keypoolsize_hd_internal": 0,
      "paytxfee": 0.00000000,
      "private_keys_enabled": true,
      "avoid_reuse": false,
      "scanning": false,
      "descriptors": false
    }
    

    System: macOS 11.1, reproduced on master

  2. jarolrod added the label Bug on Feb 23, 2021
  3. achow101 commented at 5:24 PM on February 23, 2021: member

    This is expected behavior. importprivkey does not import the key into the keypool which is what getnewaddress uses to fetch new addresses.

  4. MarcoFalke closed this on Feb 23, 2021

  5. jarolrod commented at 5:27 PM on February 23, 2021: member

    The help for importprivkey states that it adds a private key to your wallet. I take this to mean that it's populating my wallet with a private key that I can then use to generate a new address. Maybe the help message can be updated as to not cause this confusion.

  6. DrahtBot locked this on Aug 18, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me