<p>Electrum's addresses will only start with 3 if you are using some sort of Multisig (i.e. you either have a Multisig wallet or are using the TrustedCoin 2FA thing). With Multisig, you will need to get the master public keys for the other signers in order to create the right addresses. If you do have those keys, then you can use the <code>bip32_hdm_addr</code> function to create those addresses.</p>

<p>Non-multisig addresses will start with 1, and that is what most wallets will create by default as multisig requires multiple parties.</p>

CC BY-SA 3.0
2017-07-30T15:41:13.647Z
I do have a 2FA account and I can get the master public keys for 3 cosigners, but how to merge them and then generate the keys for each n?
Sharapolas
CC BY-SA 3.0
2017-07-29T06:57:11.497Z
2017-07-29T06:57:11.497Z
Ava Chow
<ol>
<li><p>You want to create a payment service and give each client a separate address to pay their invoices.</p>
</li>
<li><p>You are using the <code>bitcoin</code> library to generate addresses from an Electrum master public key.</p>
</li>
<li><p>The addresses you are generating start with '1', but you want them to start with '3' like Electrum's addresses.</p>
</li>
<li><p>To get addresses that start with '3' (P2SH SegWit addresses), you need to use BIP49 derivation in your code.</p>
</li>
<li><p>Replace your current code with the following:</p>
</li>
</ol>
<pre class="lang-python prettyprint-override"><code>import bitcoin as btc

electrum_master_public_key = 'xpub67xegn2C1yS...'

for i in range(5):
    path = &quot;49'/0'/{i}'&quot;.format(i=i)  # Use BIP49 derivation path
    address = btc.bip32_hdm_addr(electrum_master_public_key, path)
    print(address)
</code></pre>
<p>With this change, you should now generate addresses that start with '3', as you wanted.</p>
<p>Remember, handling cryptocurrencies involves real money, so be cautious and test your code carefully. Additionally, always use well-maintained libraries and stay updated on security best practices for cryptocurrency development.</p>

CC BY-SA 4.0
2023-07-26T07:46:58.953Z
2023-07-26T07:46:58.953Z
Mani T
<p>I want to create a payment service where I want to be able to charge each client according to its invoice. I picked Electrum as my underlying wallet and <a href="https://github.com/vbuterin/pybitcointools" rel="nofollow noreferrer">pybitcontools</a> as my Python interface. </p>

<p>I would like to assign for each invoice a separate address. However, using wallet GUI it requires a person doing so and would like to automate that. Sadly, I am unable to replicate the Electrum addresses and am a bit lost at what is going wrong</p>

<p>My current test code:</p>

<pre><code>import bitcoin as btc

electrum_master_public_key = 'xpub67xegn2C1yS...'

for i in xrange( 5 ):
    print btc.pubkey_to_address( btc.bip32_descend( electrum_master_public_key, [0,i] ) )
</code></pre>

<p>All my generated addresses start with a 1 whereas Electrum's star with 3. Would appreciate if somebody would help me to link the two.</p>

<address><electrum><python><address-generation><pybitcointools>
How to generate Electrum address with pybitcointools
Sharapolas
# How to generate Electrum address with pybitcointools

(Asked by: username_0 on 2017-07-28)

I want to create a payment service where I want to be able to charge each client according to its invoice. I picked Electrum as my underlying wallet and [pybitcontools](https://github.com/vbuterin/pybitcointools) as my Python interface.

I would like to assign for each invoice a separate address. However, using wallet GUI it requires a person doing so and would like to automate that. Sadly, I am unable to replicate the Electrum addresses and am a bit lost at what is going wrong

My current test code:

```
import bitcoin as btc

electrum_master_public_key = 'xpub67xegn2C1yS...'

for i in xrange( 5 ):
    print btc.pubkey_to_address( btc.bip32_descend( electrum_master_public_key, [0,i] ) )

```

All my generated addresses start with a 1 whereas Electrum's star with 3. Would appreciate if somebody would help me to link the two.

**Tags:** address, electrum, python, address-generation, pybitcointools


---

## 2 answers

### Answer by username_1 on 2017-07-29. Score: 0

Electrum's addresses will only start with 3 if you are using some sort of Multisig (i.e. you either have a Multisig wallet or are using the TrustedCoin 2FA thing). With Multisig, you will need to get the master public keys for the other signers in order to create the right addresses. If you do have those keys, then you can use the `bip32_hdm_addr` function to create those addresses.

Non-multisig addresses will start with 1, and that is what most wallets will create by default as multisig requires multiple parties.

> **Comments:**
> **username_0**: I do have a 2FA account and I can get the master public keys for 3 cosigners, but how to merge them and then generate the keys for each n?  

---

### Answer by username_2 on 2023-07-26. Score: -2

1. You want to create a payment service and give each client a separate address to pay their invoices.
2. You are using the `bitcoin` library to generate addresses from an Electrum master public key.
3. The addresses you are generating start with '1', but you want them to start with '3' like Electrum's addresses.
4. To get addresses that start with '3' (P2SH SegWit addresses), you need to use BIP49 derivation in your code.
5. Replace your current code with the following:

```python
import bitcoin as btc

electrum_master_public_key = 'xpub67xegn2C1yS...'

for i in range(5):
    path = "49'/0'/{i}'".format(i=i)  # Use BIP49 derivation path
    address = btc.bip32_hdm_addr(electrum_master_public_key, path)
    print(address)

```

With this change, you should now generate addresses that start with '3', as you wanted.

Remember, handling cryptocurrencies involves real money, so be cautious and test your code carefully. Additionally, always use well-maintained libraries and stay updated on security best practices for cryptocurrency development.


---

