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 Walletoption selected. This option means that the wallet starts out with no private keys and you can add them in later withimportprivkeyorsethdseed - 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