Author

Topic: Excuse me,how does Bitcoin Core import and export private keys? (Read 57 times)

legendary
Activity: 2618
Merit: 6452
Self-proclaimed Genius
Why are there so few features in Bitcoin Core? It's not as user-friendly as Electrum, but Electrum doesn't support viewing P2PK records. Angry!
Only the basic wallet features are user-(mainstream)-friendly in Bitcoin Core.
If you need to use commands, the wallet expects the user to have at least basic understanding of the client's RPC commands and json syntax.

Now to import P2PK; based from the quotes above,
Use importdescriptors command containing the P2PK output's "public key" inside pk descriptor.
P2PK doesn't have an address so you'll need its public key to import. (use mempool.space to see the p2pk's output's pubKey if you don't have it)

example P2PK descriptor:
Code:
"pk(043228e8f145c8c1fd8d92583c358285a358cba59791b58cc1f7ffad88ca37c9341016152f8200c39f2a82aa4107d74d706b14dbba431a516d43e0747a00e993fc)"

example import process:
First, get the checksum;
Code:
getdescriptorinfo "pk(043228e8f145c8c1fd8d92583c358285a358cba59791b58cc1f7ffad88ca37c9341016152f8200c39f2a82aa4107d74d706b14dbba431a516d43e0747a00e993fc)"
Take note of the checksum in the result, e.g.: rpwefkgf
Import the descriptor with the checksum after "#" character.
Code:
importdescriptors "[{\"desc\": \"pk(043228e8f145c8c1fd8d92583c358285a358cba59791b58cc1f7ffad88ca37c9341016152f8200c39f2a82aa4107d74d706b14dbba431a516d43e0747a00e993fc)#rpwefkgf\",\"label\": \"your_label\",\"timestamp\": 0}]"
Change the timestamp from " 0 " to " \"now\" " if you do not want to rescan right away in case if you will import more.
hero member
Activity: 868
Merit: 952
Sadly I will say bitcoin core wallet isn’t user friend like some of the SPV wallets  interms of easily exporting or importing private keys from it. It is stated that since the wallet versions (from 24.0) which creates descriptor wallets by default, the wallet is Blocking you from exporting its generated private keys.

Here is a guide on how to go round it by nc50lc

Unfortunately, dumprivkey or dumpwallet commands aren't supported by descriptor wallets.
Your option is to export the parent descriptor of that address and then use a tool that can derive the private key of that address from its master private key.

Here's the procedure (requires https://github.com/iancoleman/bip39):
  • Start Bitcoin Core, preferably on an offline machine and enter the command getaddressinfo "bc1address" and take note of the address' "parent_desc" and "ischange" values.
  • Next, enter the command listdescriptors true and find the (private) descriptor with the matching script type
    of your address' parent descriptor. (your address' should be "wpkh")
    But there'll be at least two desc with that script type, so based from your address' "ischange" value of 'true' or 'false', pick the descriptor with "internal" of the same value.
  • From the correct descriptor, copy it's master private key which is the long "xprv" key. Do not include the script type and '(' before and '/' after it.
  • Now open your iancoleman's BIP39 tool in an offline machine and paste your xprv key in "BIP32 Root Key".
  • Scroll down a bit and select the correct script type: BIP44 for legacy, BIP49 for Nested-SegWit and BIP84 for Native Segwit.
  • The default should be already correct for receiving addresses (internal: false), else, change the internal/external path from '0' to '1'.
  • Scroll-down to the derived addresses and it should be there along with its private key.
  • If your address' "address_index" is more than 20, you should derive more addresses in BIP39 tool by using the button: "Show ___ more rows" below the address list for it to show.

Also you can use the below guide again by nc50lc to also import the private key

You still can import but with a different command: use importdescriptors instead.
For a single WIF private key of a Native SegWit address, the command should look like this:
Code:
importdescriptors "[{\"desc\": \"wpkh(WIF_PRIV_KEY)#z0cazjry\", \"timestamp\": 0}]"
Use: help importdescriptors to know how to use the command.
Here's how to construct descriptors: https://github.com/bitcoin/bitcoin/blob/master/doc/descriptors.md
And to get the checksum (#z0cazjry in the example), use: getdescriptorinfo "descriptor"


Also yes you cannot simply Import public key on electrum as it doesn’t supports or recognizes it, the only the other latter addresses like the legacy, nested, native SegWit and taproot addresses are recognized

newbie
Activity: 6
Merit: 0
May I ask, how does Bitcoin Core import and export private keys, or import an address as an observation wallet? Why are there so few features in Bitcoin Core? It's not as user-friendly as Electrum, but Electrum doesn't support viewing P2PK records. Angry!
Jump to: