<p>Inspired by @NickODell answer, I created another example using nodejs that derives 5 receiving addresses and 5 change addresses.</p>

<p>You will need these two modules:
<code>npm install bitcoinjs-lib --save</code>
and
<code>npm install bip32-utils --save</code>
and <code>babel</code> for the <code>es6</code> javascript code support.</p>

<pre><code>import Bitcoin from 'bitcoinjs-lib';
import Bip32Utils from 'bip32-utils';

let hdNode = Bitcoin.HDNode.fromBase58('xpub...get.the.master.public.key.from.a.wallet.like.electrum...');

let receiving = hdNode.derive(0); // BIP32 m/0/&lt;n&gt; path (receiving addresses)
let receivingChain = new Bip32Utils.Chain(receiving);

for (var k = 0; k &lt; 5; ++k) {
    console.log(receivingChain.get());
    receivingChain.next();
}

let change = hdNode.derive(1); // BIP32 m/1/&lt;n&gt; path (change addresses)
let changeChain = new Bip32Utils.Chain(change);

for (var k = 0; k &lt; 5; ++k) {
    console.log(changeChain.get());
    changeChain.next();
}
</code></pre>

<p>Tested in electrum with a real wallet.</p>

<p>When you don't have a multiple account wallet you can use these BIP32 paths to generate addresses:</p>

<p><code>m/0/k</code>corresponds to the k'th keypair of the external chain of the HDW derived from master m.</p>

<p><code>m/1/k</code> corresponds to the k'th keypair of the internal chain of the HDW derived from master m. (internal, means change and other internal uses)</p>

<p>But when you want to use a wallet with multiple accounts, for example, one for each customer, the paths are more like this:</p>

<p><code>m/i/0/k</code> corresponds to the k'th keypair of the external chain of account number i of the HDW derived from master m.</p>

<p><code>m/i/1/k</code> corresponds to the k'th keypair of the internal chain of account number i of the HDW derived from master m.</p>

<p>This is the default wallet layout:</p>

<p><a href="https://i.sstatic.net/7jgkj.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/7jgkj.png" alt="Wallet structure"></a></p>

CC BY-SA 3.0
2017-08-31T16:34:35.150Z
This looks like a cool bit of code, but I can't honestly say that it answers the question (there is no mention of derivation paths).  This would probably be more suited as a comment linking to a github gist or something.
Jestin
CC BY-SA 3.0
2017-08-31T17:29:27.023Z
Sure, you are right. The paths are in the code but not correctly commented. edited the answer.
Pedro Simões
CC BY-SA 3.0
2017-08-31T15:53:25.007Z
2017-08-31T17:52:08.360Z
2017-08-31T17:52:08.360Z
Pedro Simões
<p>TL;DR:</p>

<blockquote>
<pre><code>BIP32 m/0/&lt;n&gt; path (receiving addresses)
BIP32 m/1/&lt;n&gt; path (change addresses)
</code></pre>
</blockquote>

<p>Some days ago I had the very same question, so I ended writing this little nodejs module that does pretty much the same that you can read on @pedro_fp_simoes' answer:</p>

<p><a href="https://www.npmjs.com/package/xpub-generator" rel="nofollow noreferrer">https://www.npmjs.com/package/xpub-generator</a>
You can use it as follows:</p>

<pre><code>import { XPubGenerator } from 'xpub-generator';

const g = new XPubGenerator('xpub....');
g.nthReceiving(1);
g.nthChange(1);
</code></pre>

CC BY-SA 3.0
2017-09-16T21:15:09.550Z
2017-09-16T21:15:09.550Z
mautematico
<p>It uses <code>m/0/&lt;n&gt;</code> for receiving addresses, and <code>m/1/&lt;n&gt;</code> for change addresses.</p>

<p>Here's some example bitcoinj code to generate receiving addresses from an extended public key.</p>

<pre><code>String serialized_xpub = "xpub.....";
unsigned int address_num = 4;
NetworkParameters params = MainNetParams.get();
DeterministicKey root_xpub = DeterministicKey.deserializeB58(null, serialized_xpub, params);

DeterministicKey receiving = HDKeyDerivation.deriveChildKey(root_xpub, new ChildNumber(0, false));
DeterministicKey new_address_key = HDKeyDerivation.deriveChildKey(receiving, new ChildNumber(address_num, false));
String new_address = new_address_key.toAddress().toString();
</code></pre>

CC BY-SA 3.0
2015-04-17T07:55:39.880Z
[possible duplicate?](http://bitcoin.stackexchange.com/a/36840/9382)
Wizard Of Ozzie
CC BY-SA 3.0
2015-04-17T08:05:40.633Z
@WizardOfOzzie Funny thing: I saw that right after I worked it out by reading the source code. "BIP32 derivation path" is totally ungoogleable, for some reason.
Nick ODell
CC BY-SA 3.0
2015-04-19T14:03:45.477Z
Just for future reference, I've been maintaining a list of deterministic wallet details, including BIP-32 derivation paths, here: https://bitcointalk.org/index.php?topic=1000544.0
Christopher Gurnee
CC BY-SA 3.0
2015-04-19T18:09:36.837Z
@ChristopherGurnee You, sir, are a gentleman and a scholar.
Nick ODell
CC BY-SA 3.0
2017-03-09T17:21:05.827Z
and for multisig? http://bitcoin.stackexchange.com/questions/51989/what-bip32-derivation-path-does-electrum-use-for-multisig
joe.js
CC BY-SA 3.0
2017-08-31T15:44:14.047Z
@NickODell Thanks for your answer. I also created another valid answer (to help others based on yours) using the nodejs bitcoinjs package, deriving 5 receive and change addresses.
Pedro Simões
CC BY-SA 3.0
2015-04-16T22:08:51.277Z
2015-10-16T06:34:43.460Z
2015-10-16T06:34:43.460Z
Nick ODell
<p>Electrum 2.0 and up uses <a href="https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki">BIP0032</a> internally. I want to write code that generates the same addresses. I can't find any information about this online.</p>

<p>What BIP32 paths does it use to generate addresses?</p>

<electrum><bip32-hd-wallets>
What BIP32 derivation path does Electrum use?
Nick ODell
# What BIP32 derivation path does Electrum use?

(Asked by: username_0 on 2015-04-16)

Electrum 2.0 and up uses [BIP0032](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) internally. I want to write code that generates the same addresses. I can't find any information about this online.

What BIP32 paths does it use to generate addresses?

**Tags:** electrum, bip32-hd-wallets


---

## 3 answers

### Answer by username_0 on 2015-04-16. Score: 11 | Accepted answer

It uses `m/0/<n>` for receiving addresses, and `m/1/<n>` for change addresses.

Here's some example bitcoinj code to generate receiving addresses from an extended public key.

```
String serialized_xpub = "xpub.....";
unsigned int address_num = 4;
NetworkParameters params = MainNetParams.get();
DeterministicKey root_xpub = DeterministicKey.deserializeB58(null, serialized_xpub, params);

DeterministicKey receiving = HDKeyDerivation.deriveChildKey(root_xpub, new ChildNumber(0, false));
DeterministicKey new_address_key = HDKeyDerivation.deriveChildKey(receiving, new ChildNumber(address_num, false));
String new_address = new_address_key.toAddress().toString();

```

> **Comments:**
> **username_4**: [possible duplicate?](http://bitcoin.stackexchange.com/a/36840/9382)  
> **username_0**: @username_4 Funny thing: I saw that right after I worked it out by reading the source code. "BIP32 derivation path" is totally ungoogleable, for some reason.  
> **username_5**: Just for future reference, I've been maintaining a list of deterministic wallet details, including BIP-32 derivation paths, here: https://bitcointalk.org/index.php?topic=1000544.0  
> **username_0**: @username_5 You, sir, are a gentleman and a scholar.  
> **username_6**: and for multisig? http://bitcoin.stackexchange.com/questions/51989/what-bip32-derivation-path-does-electrum-use-for-multisig  
> **username_1**: @username_0 Thanks for your answer. I also created another valid answer (to help others based on yours) using the nodejs bitcoinjs package, deriving 5 receive and change addresses.  

---

### Answer by username_1 on 2017-08-31. Score: 4

Inspired by @username_0 answer, I created another example using nodejs that derives 5 receiving addresses and 5 change addresses.

You will need these two modules:
`npm install bitcoinjs-lib --save`
and
`npm install bip32-utils --save`
and `babel` for the `es6` javascript code support.

```
import Bitcoin from 'bitcoinjs-lib';
import Bip32Utils from 'bip32-utils';

let hdNode = Bitcoin.HDNode.fromBase58('xpub...get.the.master.public.key.from.a.wallet.like.electrum...');

let receiving = hdNode.derive(0); // BIP32 m/0/<n> path (receiving addresses)
let receivingChain = new Bip32Utils.Chain(receiving);

for (var k = 0; k < 5; ++k) {
    console.log(receivingChain.get());
    receivingChain.next();
}

let change = hdNode.derive(1); // BIP32 m/1/<n> path (change addresses)
let changeChain = new Bip32Utils.Chain(change);

for (var k = 0; k < 5; ++k) {
    console.log(changeChain.get());
    changeChain.next();
}

```

Tested in electrum with a real wallet.

When you don't have a multiple account wallet you can use these BIP32 paths to generate addresses:

`m/0/k`corresponds to the k'th keypair of the external chain of the HDW derived from master m.

`m/1/k` corresponds to the k'th keypair of the internal chain of the HDW derived from master m. (internal, means change and other internal uses)

But when you want to use a wallet with multiple accounts, for example, one for each customer, the paths are more like this:

`m/i/0/k` corresponds to the k'th keypair of the external chain of account number i of the HDW derived from master m.

`m/i/1/k` corresponds to the k'th keypair of the internal chain of account number i of the HDW derived from master m.

This is the default wallet layout:

[![Wallet structure](https://i.sstatic.net/7jgkj.png)](https://i.sstatic.net/7jgkj.png)

> **Comments:**
> **username_2**: This looks like a cool bit of code, but I can't honestly say that it answers the question (there is no mention of derivation paths).  This would probably be more suited as a comment linking to a github gist or something.  
> **username_1**: Sure, you are right. The paths are in the code but not correctly commented. edited the answer.  

---

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

TL;DR:

> ```
> BIP32 m/0/<n> path (receiving addresses)
> BIP32 m/1/<n> path (change addresses)
>
> ```

Some days ago I had the very same question, so I ended writing this little nodejs module that does pretty much the same that you can read on @username_1\_fp\_simoes' answer:

<https://www.npmjs.com/package/xpub-generator>
You can use it as follows:

```
import { XPubGenerator } from 'xpub-generator';

const g = new XPubGenerator('xpub....');
g.nthReceiving(1);
g.nthChange(1);

```


---

