<h1>Use incremental indexes instead of random</h1>

<p>First of all, you should generate child addressess incrementally instead of randomly, as wallets will re-generate them starting from the index 0, incrementing the indexes until they start finding empty addresses.</p>

<p>From the <a href="https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#account-discovery" rel="nofollow noreferrer">BIP44 Account Discovery chapter</a>:</p>

<blockquote>
  <p>When the master seed is imported from an external source the software should start to discover the accounts in the following manner:</p>
  
  <ol>
  <li>derive the first account's node (index = 0)</li>
  <li>derive the external chain node of this account</li>
  <li>scan addresses of the external chain; respect the gap limit described below</li>
  <li>if no transactions are found on the external chain, stop discovery</li>
  <li>if there are some transactions, increase the account index and go to step 1</li>
  </ol>
  
  <p>Address gap limit</p>
  
  <p>Address gap limit is currently set to 20. If the software hits 20 unused addresses in a row, it expects there are no used addresses beyond this point and stops searching the address chain. We scan just the external chains, because internal chains receive only coins that come from the associated external chains.
  Wallet software should warn when the user is trying to exceed the gap limit on an external chain by generating a new address.</p>
</blockquote>

<p>If you generate your child keys at random indexes, most likely the first 20 indexes will be empty, so the wallet will stop the discovery and show you an empty wallet.</p>

<h1>Standard derivation paths</h1>

<p>The standard derivation path (defined in the aforementioned BIP44 standard) is the following (M denotes the master private key):</p>

<blockquote>
  <p>m / purpose' / coin_type' / account' / change / address_index</p>
</blockquote>

<p>Most wallet implementations (Electrum being a notable exception) follow this standard. That means for a given receiving address, you should use a derivation path like this:</p>

<p><code>m / 44' / 0' / 0' / 0 / 0</code></p>

<p>Which translates to bx commands like this:</p>

<p><code>cat m | bx hd-private --index 44 --hard \
       | bx hd-private --index 0 --hard \
       | bx hd-private --index 0 --hard \
       | bx hd-private --index 0 \
       | bx hd-private --index 0
</code>
Since the first three levels involve hardened derivation, you have to use the master private key. The master public key can only be used for non-hardened derivation paths.</p>

<p>Electrum doesn't implement the full BIP44 standard as it only supports single-account wallets. In Electrum, the derivation path looks like the following:</p>

<p><code>m / change / address_index</code></p>

<p>Since there is no hardened derivation on the account level, you can also import the master public key into Electrum. This is similar to the chain you described but there is an extra "change" level still.</p>

<p>Electrum can also import a BIP44 master private key (there's a checkbox in the import dialog), by making you select an account index at import time.</p>

<p>I suggest to stick to the BIP44 standard as it will be can be imported by other wallets (like Mycelium) as a HD-wallet, and will also work in Electrum if you remember to import it as a BIP44 key.</p>

<p>However, if you need to work exclusively with master <em>public</em> keys, you can still use the 2-level derivation and import them to Electrum. I'm not sure if other wallets support importing them. </p>

CC BY-SA 3.0
2017-09-10T19:02:38.517Z
2017-09-10T19:02:38.517Z
sevcsik
<p>I am confused about child HD public keys. Is this scenario correct?</p>

<ol>
<li>I am using bx (libbitcoin) for all action below.</li>
<li>Generate a seed (bx seed).</li>
<li>create master private key using seed (bx hd-new)</li>
<li>create master public key from private key (bx hd-to-public)</li>
<li>generate several child BIP32 public key using random indexes (bx hd-public)</li>
<li>use generated child keys and generate several addresses</li>
<li>now using generated addresses</li>
</ol>

<p>will all addresses connected to master private key? or because I used random indexes (step 5), it is disconnected from master private and public key?
In simple word, is it enough to use private key (step 3) in bitcoin clients such as electrum to access to all addresses that generated using child pub keys (not master key)?</p>

CC BY-SA 3.0
2016-12-05T19:47:47.460Z
It will depend on the wallet, so you should make that explicit in your question.
Pieter Wuille
CC BY-SA 3.0
2016-12-06T08:29:01.150Z
especialy bitcoin client and electrum. but also if I don't want to use any wallet, what will be needed? is master private key enough or should I generate and store child private key too?
max
CC BY-SA 4.0
2023-08-17T07:19:05.717Z
Warning: `bx seed` generates insecure seeds from [a pseudorandom number generator and very low entropy.](https://milksad.info)
Zenul_Abidin
<private-key><public-key><bip32-hd-wallets>
child keys generated addresses reflect in wallet?
max
# child keys generated addresses reflect in wallet?

(Asked by: username_0 on 2016-12-05)

I am confused about child HD public keys. Is this scenario correct?

1. I am using bx (libbitcoin) for all action below.
2. Generate a seed (bx seed).
3. create master private key using seed (bx hd-new)
4. create master public key from private key (bx hd-to-public)
5. generate several child BIP32 public key using random indexes (bx hd-public)
6. use generated child keys and generate several addresses
7. now using generated addresses

will all addresses connected to master private key? or because I used random indexes (step 5), it is disconnected from master private and public key?
In simple word, is it enough to use private key (step 3) in bitcoin clients such as electrum to access to all addresses that generated using child pub keys (not master key)?

**Tags:** private-key, public-key, bip32-hd-wallets

> **Comments:**
> **username_1**: It will depend on the wallet, so you should make that explicit in your question.  
> **username_0**: especialy bitcoin client and electrum. but also if I don't want to use any wallet, what will be needed? is master private key enough or should I generate and store child private key too?  
> **username_2**: Warning: `bx seed` generates insecure seeds from [a pseudorandom number generator and very low entropy.](https://milksad.info)  

---

## 1 answers

### Answer by username_3 on 2017-09-10. Score: 3

# Use incremental indexes instead of random

First of all, you should generate child addressess incrementally instead of randomly, as wallets will re-generate them starting from the index 0, incrementing the indexes until they start finding empty addresses.

From the [BIP44 Account Discovery chapter](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#account-discovery):

> When the master seed is imported from an external source the software should start to discover the accounts in the following manner:
>
> 1. derive the first account's node (index = 0)
> 2. derive the external chain node of this account
> 3. scan addresses of the external chain; respect the gap limit described below
> 4. if no transactions are found on the external chain, stop discovery
> 5. if there are some transactions, increase the account index and go to step 1
>
> Address gap limit
>
> Address gap limit is currently set to 20. If the software hits 20 unused addresses in a row, it expects there are no used addresses beyond this point and stops searching the address chain. We scan just the external chains, because internal chains receive only coins that come from the associated external chains.
> Wallet software should warn when the user is trying to exceed the gap limit on an external chain by generating a new address.

If you generate your child keys at random indexes, most likely the first 20 indexes will be empty, so the wallet will stop the discovery and show you an empty wallet.

# Standard derivation paths

The standard derivation path (defined in the aforementioned BIP44 standard) is the following (M denotes the master private key):

> m / purpose' / coin\_type' / account' / change / address\_index

Most wallet implementations (Electrum being a notable exception) follow this standard. That means for a given receiving address, you should use a derivation path like this:

`m / 44' / 0' / 0' / 0 / 0`

Which translates to bx commands like this:

`cat m | bx hd-private --index 44 --hard \
| bx hd-private --index 0 --hard \
| bx hd-private --index 0 --hard \
| bx hd-private --index 0 \
| bx hd-private --index 0`
Since the first three levels involve hardened derivation, you have to use the master private key. The master public key can only be used for non-hardened derivation paths.

Electrum doesn't implement the full BIP44 standard as it only supports single-account wallets. In Electrum, the derivation path looks like the following:

`m / change / address_index`

Since there is no hardened derivation on the account level, you can also import the master public key into Electrum. This is similar to the chain you described but there is an extra "change" level still.

Electrum can also import a BIP44 master private key (there's a checkbox in the import dialog), by making you select an account index at import time.

I suggest to stick to the BIP44 standard as it will be can be imported by other wallets (like Mycelium) as a HD-wallet, and will also work in Electrum if you remember to import it as a BIP44 key.

However, if you need to work exclusively with master *public* keys, you can still use the 2-level derivation and import them to Electrum. I'm not sure if other wallets support importing them.


---

