Author

Topic: help me derive in bulk (about 100) child addresses from xpub .. fast. BTC - 0.2 (Read 556 times)

legendary
Activity: 3584
Merit: 5248
https://merel.mobi => buy facemasks with BTC/LTC
A quick update: so far it seems like the OP's question was solved... He PM'ed me that he'd have to run the sollution by somebody else, and he promised he'd get back to me afterwards.

EDIT: he got back to me Smiley
https://blockchain.info/tx/0baa1793f61c6e7e3548e8d87afb1b0294d010f7880d0e5a6bfde38a01d3d9c8

A man of his word!
legendary
Activity: 3584
Merit: 5248
https://merel.mobi => buy facemasks with BTC/LTC
Thanks a lot mocacinno Smiley .  
I am not sure if there is any difference between electrum xpub and other xpub . Anyway if this works for all please Please PM your btc address.
Also which library is being used ? Feel free to only answer after receiving the 50% upfront payment.


The derivation path can differ from wallet to wallet... but by searching the correct path and adapting the script, it should work Wink

I'm running on ubuntu 16.04.1 LTS (Xenial Xerus) running python 2.7 and i have installed bitcoin-python and pybitcointools in order to write some basic scripts.
newbie
Activity: 39
Merit: 0
Thanks a lot mocacinno Smiley .  
I am not sure if there is any difference between electrum xpub and other xpub . Anyway if this works for all please Please PM your btc address.
Also which library is being used ? Feel free to only answer after receiving the 50% upfront payment. figured out the library being used: https://github.com/vbuterin/pybitcointools

Verified, solution works great!

So just need to know if it works for all xpubs and your btc address Wink
legendary
Activity: 3584
Merit: 5248
https://merel.mobi => buy facemasks with BTC/LTC
since you wanted to Do it yourself Wink
in python, this works to create the first derived address using my electrum xpub

Code:
from bitcoin import *
childkey1 = bip32_ckd('xpub_my_electrum_xpub', 0)
childkey2 = bip32_ckd(childkey1, 0)
key = bip32_extract_key(childkey2)
address = pubtoaddr(key)
print address

you'll need to put this one in a loop to browse trough all keys* , and bechmark it for speed tough... I have no idear if it's slower or faster for your implementation Wink

* for example, the derivation of the second address would be:
Code:
from bitcoin import *
childkey1 = bip32_ckd('xpub_my_electrum_xpub', 0)
childkey2 = bip32_ckd(childkey1, 1)
key = bip32_extract_key(childkey2)
address = pubtoaddr(key)
print address

EDIT: was a bit bored at work (slow day), decided to do the next part of the work for you, and i updated my post accordingly Wink
Code:
from bitcoin import *
childkey1 = bip32_ckd('xpub_my_electrum_xpub', 0)
for counter in range(1000):
        childkey2 = bip32_ckd(childkey1, counter)
        key = bip32_extract_key(childkey2)
        address = pubtoaddr(key)
        print address

Takes 5.157 seconds to generate 1000 addresses Wink, since you mentioned your old script takes 0.1s/address, and you need 0.01s/address, i guess 0.0051 is well within the requested range (it's allmost 20 times faster instead of the requested 10 times)...

Second edit, since electrum uses m/0/ for receiving addresses, and m/1/ for change addresses, generating change addresses would be done by changing line
childkey1 = bip32_ckd('xpub_my_electrum_xpub', 0)
to
childkey1 = bip32_ckd('xpub_my_electrum_xpub', 1)
member
Activity: 209
Merit: 13
newbie
Activity: 39
Merit: 0
Original Post: https://bitcointalksearch.org/topic/derive-in-batches-addresses-of-an-xpub-programmatically-1680909

Quote
For a given HD wallets public xpub (Extended public key), derive the public child addresses, in bulk.
This PHP script : https://github.com/dan-da/hd-wallet-addrs , derives public addresses, but does so one by one, which is sloww.
I am pretty sure it is possible to derive say 10 to 100 child addresses at one go. But how ? I tried digging through the above scripts code, but am unable to figure this out.

Help please!

Just to be clear, public chlid addresses  equal an address such as "14dXQGMby9q3TBAYFurAThvHBK29vr2ymg"

Thanks

btw I know I will have to check if the derived addresses have been used, but I got that part figured out! (For googlers: just send  a JSON-RPC request to the method getaddressdeltas, to get info about multiple addresses)

Job is helping me in deriving child keys from an xpub, in batches of say 100, fast! Current method takes 0.1 seconds per address which is atleast 10x times too slow for my needs.

0.2 BTC is what I am offering

NOTE: YOU DON'T HAVE TO WRITE ANY CODE. I can do that part, its understanding of how the job can be done, that I need a lot of help with.

Thanks

Edit:

I understand the public addresses (like normal bitcoin addresses) from an xpub  are derived mathematically , using some algo. Current algo being used is extremely slow, takes  9 seconds to derive 100 addresses. I just want an implementation algorithm that would derive these keys fast!
A suggested library : https://github.com/bit-wasp/secp256k1-php - goes over my head, as far as understanding what/how it can do/work.

Jump to: