End goal is to find all used addresses of a xpub programmatically, in batches, by querying a local node.

This PHP tool ( https://github.com/dan-da/hd-wallet-addrs ) extracts 'normal' addresses from an HD bitcoin wallet . Now I have to query a local bitcoin node to find out whether the extracted addresses have been used or not.

Whether an address has been used or not can easily be found out by querying the node one address at a time ( https://bitco.in/en/developer-reference#getreceivedbyaddress ). Which works but is too slow.

How can the same be done in batches ? i.e is there a Core function call or something to check info about a group of addresses ?

or any other way this can be accomplished ?



This process is in general very complicated and – missing a possible transaction – can lead to lost funds. Be careful.

With HD, you always generate publickeys. To find corresponding transaction, you need to turn them into addresses (which involves a bitcoin-script template like P2PKH). If you just going to create standard P2PKH addresses in order to find transaction, you may miss relevant transactions.

For example: For a long time, Copay used 1of1 multisig (P2SH) for single user wallets. Restoring a such xpriv HD master with just P2PKH can result in lost funds.

Also, you need to know the used BIP32 keypath scheme of the wallet you like to restore. Some wallets are using m/0'/k, some m/k, others stick to BIP44. This makes it again more complex to "regenerate" funds.

Without a fully address-index blockchain, scanning for funds can be complicated and may take serval hours.

Probably best practice is to generate a large lookup window, where the size depends on the type of the wallet. Example: if it was a merchant wallet, there are probably serval thousand key involved. This would speak for larger lookup window.

If you want to use Core, what you can do, is generating addresses in a first lookup window.


  1. generate pubkeys from m/0'/0 . m/0'/5000 (lookup-window of 5000 keys). Attention, this will not catch BIP44 wallet funds. You can use a BIP32 tool for that purpose (maybe https://github.com/libbtc/libbtc#the-bitcointool-cli).

  2. Import all these pubkeys into a new wallet (use importmulti in Core 0.14, importpubkey before 0.14 without a rescan).

  3. Restart bitcoin-core with the -rescan option.

  4. Decide if you want to extend the lookup-window (maybe if addresses up to 4900 are used), and start again with 1.)


Someone should write a script/tool/app.

  • Phew! Thanks a lot for the ideas. I like the address indexing the blockchain. Will see if its feasible. btw Are there any other options besides using Core functions (I am open to everything) ? – gyaani_guy Nov 11 '16 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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