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

1 Answer 1


If you are comfortable with using the command line then 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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