Bitcoin Forum
April 26, 2024, 03:10:23 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Generating addresses for accepting payments  (Read 191 times)
ryselis (OP)
Newbie
*
Offline Offline

Activity: 1
Merit: 0


View Profile
July 05, 2018, 06:29:05 AM
 #1

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?
1714101023
Hero Member
*
Offline Offline

Posts: 1714101023

View Profile Personal Message (Offline)

Ignore
1714101023
Reply with quote  #2

1714101023
Report to moderator
"You Asked For Change, We Gave You Coins" -- casascius
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3374
Merit: 6535


Just writing some code


View Profile WWW
July 05, 2018, 06:50:14 AM
 #2

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?

Abdussamad
Legendary
*
Offline Offline

Activity: 3598
Merit: 1560



View Profile
July 05, 2018, 02:54:38 PM
Merited by suchmoon (5)
 #3

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
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3374
Merit: 6535


Just writing some code


View Profile WWW
July 05, 2018, 07:56:27 PM
Merited by bob123 (1)
 #4

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.

Abdussamad
Legendary
*
Offline Offline

Activity: 3598
Merit: 1560



View Profile
July 06, 2018, 11:54:25 AM
Last edit: July 06, 2018, 12:26:27 PM by Abdussamad
 #5

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.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!