Network: BCH testnet
Client: bitcoin-abc-0.18/bin/bitcoind and bitcoin-cli

I want to convert xPrivKey which is from exported Bitpay wallet file to private key for using bitcoin-cli importprivkey

Thank you.

xPrivKey is a BIP32 extended key. This can be used to derive child addresses.

importprivkey expects a WIF Wallet Import Format.

In order to convert to from the extended to compressed format, all you need to do is decode from Base58Check and grab the last 32 bytes (33 for public keys). See BIP32 - Extended Key Serialization and then encode to WIF format:

$ printf "xprv9uHRZZhk6KAJC1avXpDAp4MDc3sQKNxDiPvvkX8Br5ngLNv1TxvUxt4cV1rGL5hj6KCesnDYUhd7oWgT11eZG7XnxHrnYeSvkzY7d2bhkJ7" | base58 -dc | xxd -p 0488ade4013442193e8000000047fdacbd0f1097043b78c63c20c34ef4ed9a111d980047ad16282c7ae623614100edb2e14f9ee77d26dd93b4ecede8d16ed408ce149b6cd80b0715a2d911a0afea

The last 64 characters (32 bytes) represent the hex version of the private key.

edb2e14f9ee77d26dd93b4ecede8d16ed408ce149b6cd80b0715a2d911a0afea

Then convert to WIF:

$ priv="edb2e14f9ee77d26dd93b4ecede8d16ed408ce149b6cd80b0715a2d911a0afea"
$ # 0x80 for mainnet, 0xef for testnet
$ pub_suffix=01 # append 01 if the corresponding public key is compressed
$ mainnet_prefix=80
$ ext_priv_mainnet=$mainnet_prefix$priv
$ wif_enc_mainnet_compressed=$(printf "$ext_priv_mainnet$pub_suffix" | xxd -r -p | base58 -c)
$ echo "WIF Mainnet (Compressed): "$wif_enc_mainnet_compressed

WIF Mainnet (Compressed): L5BmPijJjrKbiUfG4zbiFKNqkvuJ8usooJmzuD7Z8dkRoTThYnAT
  • where are you getting this base58 program? – Abdussamad Nov 28 at 15:59
  • Good question, I think it was pip install base58 – JBaczuk Nov 28 at 16:21

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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