0

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

2 Answers 2

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.

1
  • 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
    Commented Jul 30, 2017 at 15:41
-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:

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.