<p>This process is in general very complicated and – missing a possible transaction – can lead to lost funds. Be careful.</p>
<p>With HD, you always generate <code>publickeys</code>. 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.</p>
<p>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.</p>
<p>Also, you need to know the used BIP32 keypath scheme of the wallet you like to restore. Some wallets are using <code>m/0'/k</code>, some <code>m/k</code>, others stick to BIP44. This makes it again more complex to &quot;regenerate&quot; funds.</p>
<hr />
<p>Without a fully address-index blockchain, scanning for funds can be complicated and may take serval hours.</p>
<p>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.</p>
<p>If you want to use Core, what you can do, is generating addresses in a first lookup window.</p>
<h3>Example:</h3>
<ol>
<li><p>generate pubkeys from <code>m/0'/0</code> . <code>m/0'/5000</code> (lookup-window of 5000 keys). <strong>Attention, this will not catch BIP44 wallet funds</strong>.
You can use a BIP32 tool for that purpose (maybe <a href="https://github.com/libbtc/libbtc#the-bitcointool-cli" rel="nofollow noreferrer">https://github.com/libbtc/libbtc#the-bitcointool-cli</a>).</p>
</li>
<li><p>Import all these pubkeys into a new wallet (use <code>importmulti</code> in Core 0.14, <code>importpubkey</code> before 0.14 without a rescan).</p>
</li>
<li><p>Restart bitcoin-core with the <code>-rescan</code> option.</p>
</li>
<li><p>Decide if you want to extend the lookup-window (maybe if addresses up to 4900 are used), and start again with 1.)</p>
</li>
</ol>
<h3>TL/TR:</h3>
<p><strong>Someone should write a script/tool/app.</strong></p>

CC BY-SA 3.0
2016-11-11T10:04:13.897Z
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
CC BY-SA 3.0
2016-11-11T09:45:56.507Z
2016-11-11T09:45:56.507Z
2020-06-16T11:10:03.350Z
Jonas Schnelli
<p>End goal is to find all used addresses of a xpub programmatically, in batches, by querying a local node.</p>

<p>This PHP tool ( <a href="https://github.com/dan-da/hd-wallet-addrs" rel="nofollow noreferrer">https://github.com/dan-da/hd-wallet-addrs</a> ) 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. </p>

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

<p>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 ? </p>

<p>or any other way this can be accomplished ?</p>

<p>Thanks</p>

<transactions><address><bip32-hd-wallets>
Find used addresses of an HD wallet xpub (Extended private Key)
gyaani_guy
# Find used addresses of an HD wallet xpub (Extended private Key)

(Asked by: username_0 on 2016-11-11)

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 ?

Thanks

**Tags:** transactions, address, bip32-hd-wallets


---

## 1 answers

### Answer by username_1 on 2016-11-11. Score: 1

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.

### Example:

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

### TL/TR:

**Someone should write a script/tool/app.**

> **Comments:**
> **username_0**: 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) ?  

---

