<p>You're very close.</p>

<p><code>bip32_ckd</code> returns a <a href="https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys" rel="nofollow">BIP-32 <em>extended</em> public key</a>, however pubtoaddr expects as input a "normal" non-extended public key in either raw or hex-encoded form (and it doesn't check if the public key appears valid). Here's what you want:</p>

<pre><code>./pybtctools bip32_ckd $xpub 0
&gt; $xpub0

./pybtctools bip32_ckd $xpub0 0
&gt; $xpub00

./pybtctools bip32_extract_key $xpub00
&gt; $pub00

./pybtctools pubtoaddr $pub00
&gt; $addr
</code></pre>

CC BY-SA 3.0
2015-08-08T03:40:10.477Z
Great answer. Helped me understand how Electrum derives the keys it uses from the extended private keys.

It drives me nuts when all these other wallets (trezor, mycelium, etc) all use different formulas to derive addresses.
Aaron Vallance
CC BY-SA 3.0
2015-05-27T15:42:08.153Z
2015-05-27T15:42:08.153Z
Christopher Gurnee
<p>I'm trying to create a BIP32 storefront that uses Electrum's key derivation path. The user passes me their MPK, and with every order I generate a new address based on the MPK. I'm able to generate addresses, but they don't match the one's created by Electrum. I'm using Electrum 2.2.</p>

<p>This is my code (I'm using pybitcointools command line). To keep thinks legible, I'm swapping out the actual values for <code>$variables</code>.</p>

<pre><code>&gt; Using $xpub which is the MPK I copied from Electrum:
./pybtctools bip32_ckd $xpub 0
&gt; $xpub0

./pybtctools bip32_ckd $xpub0 0
&gt; $xpub00

./pybtctools pubtoaddr $xpub00
&gt; $addr
</code></pre>

<p>My expectation is that the<code>$addr</code> I end up with should match the the first address of my "receiving" addresses in Electrum. However, they don't match. Any thoughts on why that might be?</p>

<p>For reference the xpub I start with <code>xpub661MyMwAqRbcGK5eE2eSWmnU4Pg6knZZqZEmREAgZ4vj6z3B5soecps7UJj37NF9aWhjEMQoyH9xgcC14KUgEGX9avagrdv9rcN56wjwXR2</code> and I get an address of <code>17VzXFqo6Kg7vMxNLWD5hhwgsdCV6XL9RT</code> (which is not in my Receiving addresses list).</p>

<electrum><bip32-hd-wallets>
Having problem implementing Electrum's BIP32 Key deriviation path
Akhil F
# Having problem implementing Electrum's BIP32 Key deriviation path

(Asked by: username_0 on 2015-05-27)

I'm trying to create a BIP32 storefront that uses Electrum's key derivation path. The user passes me their MPK, and with every order I generate a new address based on the MPK. I'm able to generate addresses, but they don't match the one's created by Electrum. I'm using Electrum 2.2.

This is my code (I'm using pybitcointools command line). To keep thinks legible, I'm swapping out the actual values for `$variables`.

```
> Using $xpub which is the MPK I copied from Electrum:
./pybtctools bip32_ckd $xpub 0
> $xpub0

./pybtctools bip32_ckd $xpub0 0
> $xpub00

./pybtctools pubtoaddr $xpub00
> $addr

```

My expectation is that the`$addr` I end up with should match the the first address of my "receiving" addresses in Electrum. However, they don't match. Any thoughts on why that might be?

For reference the xpub I start with `xpub661MyMwAqRbcGK5eE2eSWmnU4Pg6knZZqZEmREAgZ4vj6z3B5soecps7UJj37NF9aWhjEMQoyH9xgcC14KUgEGX9avagrdv9rcN56wjwXR2` and I get an address of `17VzXFqo6Kg7vMxNLWD5hhwgsdCV6XL9RT` (which is not in my Receiving addresses list).

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


---

## 1 answers

### Answer by username_1 on 2015-05-27. Score: 3 | Accepted answer

You're very close.

`bip32_ckd` returns a [BIP-32 *extended* public key](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys), however pubtoaddr expects as input a "normal" non-extended public key in either raw or hex-encoded form (and it doesn't check if the public key appears valid). Here's what you want:

```
./pybtctools bip32_ckd $xpub 0
> $xpub0

./pybtctools bip32_ckd $xpub0 0
> $xpub00

./pybtctools bip32_extract_key $xpub00
> $pub00

./pybtctools pubtoaddr $pub00
> $addr

```

> **Comments:**
> **username_2**: Great answer. Helped me understand how Electrum derives the keys it uses from the extended private keys.  It drives me nuts when all these other wallets (trezor, mycelium, etc) all use different formulas to derive addresses.  

---

