<p>You want to use bip32_bin_extract_key on the bip32_masterpublickey:</p>

<p><a href="https://github.com/vbuterin/pybitcointools/blob/8e8a33d7281c871950519e5f256ad08cf0d5df69/bitcoin/deterministic.py#L140" rel="nofollow">https://github.com/vbuterin/pybitcointools/blob/8e8a33d7281c871950519e5f256ad08cf0d5df69/bitcoin/deterministic.py#L140</a></p>

<p>And then use pubkey_to_address on the result:</p>

<p><a href="https://github.com/vbuterin/pybitcointools/blob/8e8a33d7281c871950519e5f256ad08cf0d5df69/bitcoin/main.py#L446" rel="nofollow">https://github.com/vbuterin/pybitcointools/blob/8e8a33d7281c871950519e5f256ad08cf0d5df69/bitcoin/main.py#L446</a></p>

<p>simply put:</p>

<pre><code>btc.pubkey_to_address(btc.bip32_bin_extract_key(bip32_masterpublickey))
</code></pre>

CC BY-SA 3.0
2016-07-22T04:57:05.620Z
That would generate one bitcoin address, right? How do I generate two or more using the master public key?
shackra
CC BY-SA 3.0
2016-07-22T13:45:58.150Z
Indeed, that would. You'll want to do bip32_descend to get keys that are not the root key.
Jimmy Song
CC BY-SA 3.0
2016-07-22T21:42:52.160Z
Sorry for being annoying, but what parameters should I exactly feed `bip32_descend` with, besides the public master key (I guess) to achieve what I'm looking? I did this `btc.pubkey_to_address(btc.bip32_descend(bip32_masterpublickey, [1, 0, 0]))` and I'm getting a different address changing the third 0 of the list, but I'm not sure if that equals to `M/i'/0`
shackra
CC BY-SA 3.0
2016-07-23T15:41:55.760Z
So the last argument is the BIP32 path. [1,0,0] => M/1/0/0 path. Changing any of the numbers in the path or making it longer by an element will change the address.
Jimmy Song
CC BY-SA 3.0
2016-07-22T03:49:56.330Z
2016-07-22T03:49:56.330Z
Jimmy Song
<p>I'm goofing around with this fork of <a href="https://github.com/wizardofozzie/pybitcointools" rel="nofollow">pybitcointools</a> and I got stock with generating <strong>multiple</strong> address for receiving coins with a master public key. So far, this is what I have:</p>

<pre><code>import bitcoin as btc

privatekey = btc.sha256("large example seed for this great test")
print privatekey

# 03e02b95a485112b543ac29cd262afbbd64dca9b4496e264e47312cb193ae5ab

bip32_masterprivatekey = btc.bip32_master_key(privatekey)
bip32_masterpublickey = btc.bip32_privtopub(bip32_masterprivatekey)

print bip32_masterprivatekey
# xprv9s21ZrQH143K3tQmGrVtKc7B6ZPtCJAmD6wDAJXxb7YXAoZFTb55UroSxrU7k823vSQmYPDhdseRKqP1mgSUWDneinai2seUd7RLX2xkmGW

print bip32_masterpublickey
# xpub661MyMwAqRbcGNVENt2tgk3uebENbktcaKroxgwa9T5W3btQ18PL2f7vp78LNoioGhZcgSH1i2cH48YcQttiEaAh86TuJpsUu2J7jQWnmbC
</code></pre>

<bip32-hd-wallets><address-generation>
How do I generate multiple address with a master public key in pybitcointools?
shackra
# How do I generate multiple address with a master public key in pybitcointools?

(Asked by: username_0 on 2016-07-22)

I'm goofing around with this fork of [pybitcointools](https://github.com/wizardofozzie/pybitcointools) and I got stock with generating **multiple** address for receiving coins with a master public key. So far, this is what I have:

```
import bitcoin as btc

privatekey = btc.sha256("large example seed for this great test")
print privatekey

# 03e02b95a485112b543ac29cd262afbbd64dca9b4496e264e47312cb193ae5ab

bip32_masterprivatekey = btc.bip32_master_key(privatekey)
bip32_masterpublickey = btc.bip32_privtopub(bip32_masterprivatekey)

print bip32_masterprivatekey
# xprv9s21ZrQH143K3tQmGrVtKc7B6ZPtCJAmD6wDAJXxb7YXAoZFTb55UroSxrU7k823vSQmYPDhdseRKqP1mgSUWDneinai2seUd7RLX2xkmGW

print bip32_masterpublickey
# xpub661MyMwAqRbcGNVENt2tgk3uebENbktcaKroxgwa9T5W3btQ18PL2f7vp78LNoioGhZcgSH1i2cH48YcQttiEaAh86TuJpsUu2J7jQWnmbC

```

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


---

## 1 answers

### Answer by username_1 on 2016-07-22. Score: 2 | Accepted answer

You want to use bip32\_bin\_extract\_key on the bip32\_masterpublickey:

<https://github.com/vbuterin/pybitcointools/blob/8e8a33d7281c871950519e5f256ad08cf0d5df69/bitcoin/deterministic.py#L140>

And then use pubkey\_to\_address on the result:

<https://github.com/vbuterin/pybitcointools/blob/8e8a33d7281c871950519e5f256ad08cf0d5df69/bitcoin/main.py#L446>

simply put:

```
btc.pubkey_to_address(btc.bip32_bin_extract_key(bip32_masterpublickey))

```

> **Comments:**
> **username_0**: That would generate one bitcoin address, right? How do I generate two or more using the master public key?  
> **username_1**: Indeed, that would. You'll want to do bip32_descend to get keys that are not the root key.  
> **username_0**: Sorry for being annoying, but what parameters should I exactly feed `bip32_descend` with, besides the public master key (I guess) to achieve what I'm looking? I did this `btc.pubkey_to_address(btc.bip32_descend(bip32_masterpublickey, [1, 0, 0]))` and I'm getting a different address changing the third 0 of the list, but I'm not sure if that equals to `M/i'/0`  
> **username_1**: So the last argument is the BIP32 path. [1,0,0] => M/1/0/0 path. Changing any of the numbers in the path or making it longer by an element will change the address.  

---

