<p><code>xpub = 'ypub6...</code><br>
<code>(network="BTC",...</code>    </p>

<p>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. </p>

CC BY-SA 4.0
2018-06-03T02:29:44.347Z
2018-06-03T02:29:44.347Z
m1xolyd1an
<p>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?</p>

<p>pywallet:</p>

<pre><code>from pywallet import wallet
xpub = 'ypub6Y9NsCaunfAtedv6VX7UTfuvQGLu1TgMtLtjnRydESqWwUSkJnAzATyCzscezpcfoXtgJhAfUTauEQWWt8xvbLxo7qXToCDkJi1Nb1b7wZB'
wallet.create_address(network="BTC", xpub=pub, child=0)
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  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
    version)
pywallet.utils.keys.IncompatibleNetworkException: Incorrect network. Bitcoin Main Net expects a byte prefix of 76067358, but you supplied b'\x04\x9d|\xb2'
</code></pre>

<p>The <code>pybitcointools</code> do generate an address, but they do not match the one Trezor generates.</p>

<p>Essentially I need code which replicated Trezor address generation from <code>xPub</code>. Any ideas? </p>

<bip32-hd-wallets><python><address-generation><trezor>
Generate addresses from Trezor's xPub using Python
Katafalkas
# Generate addresses from Trezor's xPub using Python

(Asked by: username_0 on 2017-12-23)

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?
pywallet:
from pywallet import wallet
xpub = 'ypub6Y9NsCaunfAtedv6VX7UTfuvQGLu1TgMtLtjnRydESqWwUSkJnAzATyCzscezpcfoXtgJhAfUTauEQWWt8xvbLxo7qXToCDkJi1Nb1b7wZB'
wallet.create_address(network="BTC", xpub=pub, child=0)
Traceback (most recent call last):
  File "", line 1, in 
  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
    version)
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?

**Tags:** bip32-hd-wallets, python, address-generation, trezor


---

## 1 answers

### Answer by username_1 on 2018-06-03. Score: 0

`xpub = 'ypub6...`  
`(network="BTC",...`

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.


---

