Having problem implementing Electrum's BIP32 Key deriviation path 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.

&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


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).
You're very close.

bip32_ckd returns a BIP-32 extended public key, 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
&gt; $xpub0

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

./pybtctools bip32_extract_key $xpub00
&gt; $pub00

./pybtctools pubtoaddr $pub00
&gt; $addr