<p><code>xPrivKey</code> is a <a href="https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys" rel="nofollow noreferrer">BIP32 extended key</a>. This can be used to derive child addresses.</p>

<p><code>importprivkey</code> expects a <code>WIF</code> <a href="https://en.bitcoin.it/wiki/Wallet_import_format" rel="nofollow noreferrer">Wallet Import Format</a>.</p>

<p>In order to convert to from the extended to compressed format, all you need to do is decode from <a href="https://en.bitcoin.it/wiki/Base58Check_encoding" rel="nofollow noreferrer">Base58Check</a> and grab the last 32 bytes (33 for public keys). See <a href="https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#serialization-format" rel="nofollow noreferrer">BIP32 - Extended Key Serialization</a> and then encode to WIF format:</p>

<p><code>$ printf "xprv9uHRZZhk6KAJC1avXpDAp4MDc3sQKNxDiPvvkX8Br5ngLNv1TxvUxt4cV1rGL5hj6KCesnDYUhd7oWgT11eZG7XnxHrnYeSvkzY7d2bhkJ7" | base58 -dc | xxd -p 0488ade4013442193e8000000047fdacbd0f1097043b78c63c20c34ef4ed9a111d980047ad16282c7ae623614100edb2e14f9ee77d26dd93b4ecede8d16ed408ce149b6cd80b0715a2d911a0afea</code></p>

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

<p><code>edb2e14f9ee77d26dd93b4ecede8d16ed408ce149b6cd80b0715a2d911a0afea</code></p>

<p>Then convert to WIF:</p>

<pre><code>$ 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
</code></pre>

CC BY-SA 4.0
2018-11-28T15:59:14.770Z
where are you getting this base58 program?
Abdussamad
CC BY-SA 4.0
2018-11-28T16:21:40.157Z
Good question, I think it was `pip install base58`
JBaczuk
CC BY-SA 4.0
2018-11-28T15:03:24.257Z
2018-11-28T15:10:38.193Z
2018-11-28T15:10:38.193Z
JBaczuk
<p>Network: BCH testnet<br>
Client: bitcoin-abc-0.18/bin/bitcoind and bitcoin-cli</p>

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

<p>Thank you.</p>

<bitcoin-core><bitcoind><private-key><bitpay><private-key-import>
Bitpay xPrivKey to private key
Jungsoo Nam
# Bitpay xPrivKey to private key

(Asked by: username_0 on 2018-11-27)

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.

**Tags:** bitcoin-core, bitcoind, private-key, bitpay, private-key-import


---

## 1 answers

### Answer by username_1 on 2018-11-28. Score: 1

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

> **Comments:**
> **username_2**: where are you getting this base58 program?  
> **username_1**: Good question, I think it was `pip install base58`  

---

