I am trying to generate BIP32 HD addresses from my Trezors xPub key. I keep getting errors with most of the libs our there. What am I missing?


from pywallet import wallet
xpub = 'ypub6Y9NsCaunfAtedv6VX7UTfuvQGLu1TgMtLtjnRydESqWwUSkJnAzATyCzscezpcfoXtgJhAfUTauEQWWt8xvbLxo7qXToCDkJi1Nb1b7wZB'
wallet.create_address(network="BTC", xpub=pub, child=0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/pywallet/wallet.py", line 48, in create_address
    wallet_obj = Wallet.deserialize(xpub, network=network.upper())
  File "/usr/local/lib/python3.5/dist-packages/pywallet/utils/bip32.py", line 557, in deserialize
pywallet.utils.keys.IncompatibleNetworkException: Incorrect network. Bitcoin Main Net expects a byte prefix of 76067358, but you supplied b'\x04\x9d|\xb2'

The pybitcointools do generate an address, but they do not match the one Trezor generates.

Essentially I need code which replicated Trezor address generation from xPub. Any ideas?


xpub = 'ypub6...

You are providing a testnet extended public key with the network parameter set as mainnet. I would suggest you either use a mainnet xpub key, or change the network parameter to testnet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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