Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: ryselis on July 05, 2018, 06:29:05 AM



Title: Generating addresses for accepting payments
Post by: ryselis on July 05, 2018, 06:29:05 AM
My goal: given wallet's xpub address, generate unique addresses to accept payments.

My current solution:

I am using Python's library pywallet (https://pypi.org/project/pywallet/) to achive this.

I have created 2 wallets in testnet using Copay wallet, 1 to simulate payer, 1 to simulate receiver. I have taken sender's xpub address, and tried generating addresses like this:


Code:
WALLET_PUBKEY = <xpub>
from pywallet import wallet
user_addr = wallet.create_address(network="btctest", xpub=WALLET_PUBKEY, child=0)
print(user_addr)

this gives me the following output:

Code:
{'path': 'm/2147483649/0',
 'bip32_path': "m/44'/0'/0'/2147483649/0",
 'address': '1MaQRP6S5s1EjS3TiziduBKNoEBtPwsrS4'}

However, if I transfer bitcoins to 1MaQRP6S5s1EjS3TiziduBKNoEBtPwsrS4, the receiver wallet does not get the funds. What am I doing wrong?


Title: Re: Generating addresses for accepting payments
Post by: achow101 on July 05, 2018, 06:50:14 AM
The address format is incorrect for testnet. Your addresses should start with m or n, not 1.

the receiver wallet does not get the funds. What am I doing wrong?
How did you determine that it did not receive the funds? Are you checking a testnet block explorer or are you expecting some sort of notification from the library that there was a transaction?


Title: Re: Generating addresses for accepting payments
Post by: Abdussamad on July 05, 2018, 02:54:38 PM
The derivation path is way out there. Instead of 2147.. something you should use 0. That part can only be 0 for external addresses and 1 for change addresses.

m/44'/0'/0'/0/i where i is in the index of the address (first is 0, second is 1 and so on).

The above is for mainnet address. If you want to generate testnet addresses then the purpose must be changed to 1 and you have to change the version bit in the addresses as well. So the derivation path for testnet is:

m/44'/1'/0'/0/i


More info about bip44 here: https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#Path_levels


Title: Re: Generating addresses for accepting payments
Post by: achow101 on July 05, 2018, 07:56:27 PM
The derivation path is way out there. Instead of 2147.. something you should use 0. That part can only be 0 for external addresses and 1 for change addresses.
That's just another way to write the derivation path for 1'. Hardened derivation are indexes beginning at 2147483648, but for simplicity we use ' or h to indicate this.


Title: Re: Generating addresses for accepting payments
Post by: Abdussamad on July 06, 2018, 11:54:25 AM
ok but bip44 wallets don't expect that part to be hardened. there is no hardening below the account level.

also you obviously can't generate hardened addresses using just the xpub on the server.