<p>If you are comfortable with using the command line then <a href="https://github.com/libbitcoin/libbitcoin-explorer" rel="nofollow noreferrer">libbitcoin-explorer</a> is a great utility for converting your bitcoin HD keys. It even works completely offline. </p>

<p>Once you have <code>bx</code> installed, you can run the <code>hd-to-public</code> command like so:</p>

<pre><code>$ bx hd-to-public xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi
=&gt; xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8
</code></pre>

<p>More info about the other HD Key related commands for libbitcoin-explorer can be found here: <a href="https://github.com/libbitcoin/libbitcoin-explorer/wiki/bx-hd-to-public" rel="nofollow noreferrer">https://github.com/libbitcoin/libbitcoin-explorer/wiki/bx-hd-to-public</a></p>

CC BY-SA 4.0
2019-09-02T17:21:25.157Z
2019-09-02T17:21:25.157Z
lastcanal
<p>I'm looking for a script/pseudocode/utility (preferably, code in javascript/c++ or a secure, verified and open-source rpc client) that can convert a given xpriv to xpub.</p>

<p>Only one I've found (but not tried yet) is this one  :
<a href="https://github.com/sarchar/brainwallet.github.com/tree/bip32" rel="nofollow noreferrer">https://github.com/sarchar/brainwallet.github.com/tree/bip32</a></p>

<p>or I know electrum wallet client can do it. I would prefer to read through the code of a standalone script though and/or create my own script</p>

<bip32-hd-wallets><xpub>
Best script/pseudocode to convert xpriv to xpub?
WhoIsNinja
# Best script/pseudocode to convert xpriv to xpub?

(Asked by: username_0 on 2019-09-02)

I'm looking for a script/pseudocode/utility (preferably, code in javascript/c++ or a secure, verified and open-source rpc client) that can convert a given xpriv to xpub.

Only one I've found (but not tried yet) is this one :
<https://github.com/sarchar/brainwallet.github.com/tree/bip32>

or I know electrum wallet client can do it. I would prefer to read through the code of a standalone script though and/or create my own script

**Tags:** bip32-hd-wallets, xpub


---

## 1 answers

### Answer by username_1 on 2019-09-02. Score: 4 | Accepted answer

If you are comfortable with using the command line then [libbitcoin-explorer](https://github.com/libbitcoin/libbitcoin-explorer) is a great utility for converting your bitcoin HD keys. It even works completely offline.

Once you have `bx` installed, you can run the `hd-to-public` command like so:

```
$ bx hd-to-public xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi
=> xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8

```

More info about the other HD Key related commands for libbitcoin-explorer can be found here: <https://github.com/libbitcoin/libbitcoin-explorer/wiki/bx-hd-to-public>


---

