<p>A public key can have multiple addresses. It looks like what is happening here is that Electrum is creating a P2SH-P2WPKH type address while your NodeJS code is creating a P2PKH address. These are two different address types which have different spending requirements and transaction data. However Bitcoin sent to either address type can still be spent with the same private key and the same public key was used to create both addresses.</p>

<p>When you sent the Bitcoin to the P2PKH address, Electrum won't show it because it is not looking for Bitcoin sent to that address. Just because you have the private key necessary to spend some Bitcoin does not necessarily mean that your wallet will be looking for outputs of that kind. A wallet cannot track all possible output scripts that it can spend (it is infinite), it can only track the ones it is expecting to see. So for Electrum, it's only tracking the P2SH-P2WPKH address and not the P2PKH address that you sent Bitcoin to.</p>

CC BY-SA 4.0
2019-03-19T00:54:02.107Z
I see, so the bitcoin address given by Ledger is indeed connected to my wallet, but it isn't tracked. Then I suppose I have to get both apps to either use P2PKH or P2SH-P2WPKH. After that I need to find some way to either track the address given by LedgerJS in the Electrum app... Or I need to get an address from Electrum and use it in LedgerJS. Either way you have my gratitude, your elaborate answer has helped me greatly.
CoderApprentice
CC BY-SA 4.0
2019-03-18T20:08:02.123Z
2019-03-18T20:08:02.123Z
Ava Chow
<p>I start Electrum in my cmdline like this:</p>

<pre><code>./Electrum --testnet
</code></pre>

<p>I connect Ledger Nano S to my laptop.
In Electrum I make a new HD Wallet with Derivation path using the Nano S's private key as seed:</p>

<pre><code>"m/49'/1'/0'"
</code></pre>

<p>In NodeJS (LedgerJS library) I write this code, using the exact same derivation path, also using the Nano S private key as seed:</p>

<pre><code>const transport = await TransportNodeHid.create();
const btc = new AppBtc(transport);
const result = await btc.getWalletPublicKey("m/49'/1'/0'");
console.log(result.getWalletPublicKey())
</code></pre>

<p>Now, since the TransportNodeHid connects to my Ledger Nano S, I expect that the AppBtc object generates a HD Wallet with the exact same seed, and therefore the derivation path</p>

<pre><code>"m/49'/1'/0'"
</code></pre>

<p>should give me the exact same Wallet Master Public key and receiving Bitcoin address right?</p>

<p>However, in Electrum:</p>

<pre><code>Master Public Key: upub5EorGi4nr15AW.....
Receiving Address: 2NEYbAH7x6sXU2bS....
</code></pre>

<p>and in my NodeJS application, using getWalletPublicKey():</p>

<pre><code>{ 
    publicKey:'049bd7786109d5bed56.....',
    bitcoinAddress: 'mtCKwjnNzNZr.....',
    chainCode:'c511f1afedb628fdb93299747604b...'
}
</code></pre>

<p>Now, I figured out that the publicKey and chainCode that the NodeJS code returns can be combined somehow to create the Master Public Key. However, the bitcoinAddress property should be the address associated with my HD wallet right? It's different from the receiving address in the Electrum app, but it should still be <em>a</em> receiving address.</p>

<p>However I already tried sending 0.0001 BTC to it with Testnet but it never arrived in my Electrum Wallet. So does this mean that this address is not associated with my Electrum Wallet? Even though I gave the exact same Derivation Path and used the exact same seed (hardware device Ledger Nano S)?</p>

<p>How can I "get" more receiving Address from my HD Wallet using the LedgerJS library?</p>

<p>I have checked LedgerJS documentation and examples, but I wouldn't go so far as to call it "documentation", because most functionality is barely explained and examples are virtually non-existent. There's a lot of guesswork involved in how exactly everything works. </p>

<p><a href="https://github.com/LedgerHQ/ledgerjs/tree/master/packages/hw-app-btc#getwalletpublickey" rel="nofollow noreferrer">https://github.com/LedgerHQ/ledgerjs/tree/master/packages/hw-app-btc#getwalletpublickey</a></p>

<p><a href="http://ledgerhq.github.io/ledgerjs/docs" rel="nofollow noreferrer">http://ledgerhq.github.io/ledgerjs/docs</a></p>

<electrum><bip32-hd-wallets><ledger-hardware-wallet>
Why do LedgerJS and Electrum, using the same Nano S and derivation path, not refer to the same Wallet?
CoderApprentice
# Why do LedgerJS and Electrum, using the same Nano S and derivation path, not refer to the same Wallet?

(Asked by: username_0 on 2019-03-18)

I start Electrum in my cmdline like this:

```
./Electrum --testnet

```

I connect Ledger Nano S to my laptop.
In Electrum I make a new HD Wallet with Derivation path using the Nano S's private key as seed:

```
"m/49'/1'/0'"

```

In NodeJS (LedgerJS library) I write this code, using the exact same derivation path, also using the Nano S private key as seed:

```
const transport = await TransportNodeHid.create();
const btc = new AppBtc(transport);
const result = await btc.getWalletPublicKey("m/49'/1'/0'");
console.log(result.getWalletPublicKey())

```

Now, since the TransportNodeHid connects to my Ledger Nano S, I expect that the AppBtc object generates a HD Wallet with the exact same seed, and therefore the derivation path

```
"m/49'/1'/0'"

```

should give me the exact same Wallet Master Public key and receiving Bitcoin address right?

However, in Electrum:

```
Master Public Key: upub5EorGi4nr15AW.....
Receiving Address: 2NEYbAH7x6sXU2bS....

```

and in my NodeJS application, using getWalletPublicKey():

```
{ 
    publicKey:'049bd7786109d5bed56.....',
    bitcoinAddress: 'mtCKwjnNzNZr.....',
    chainCode:'c511f1afedb628fdb93299747604b...'
}

```

Now, I figured out that the publicKey and chainCode that the NodeJS code returns can be combined somehow to create the Master Public Key. However, the bitcoinAddress property should be the address associated with my HD wallet right? It's different from the receiving address in the Electrum app, but it should still be *a* receiving address.

However I already tried sending 0.0001 BTC to it with Testnet but it never arrived in my Electrum Wallet. So does this mean that this address is not associated with my Electrum Wallet? Even though I gave the exact same Derivation Path and used the exact same seed (hardware device Ledger Nano S)?

How can I "get" more receiving Address from my HD Wallet using the LedgerJS library?

I have checked LedgerJS documentation and examples, but I wouldn't go so far as to call it "documentation", because most functionality is barely explained and examples are virtually non-existent. There's a lot of guesswork involved in how exactly everything works.

<https://github.com/LedgerHQ/ledgerjs/tree/master/packages/hw-app-btc#getwalletpublickey>

<http://ledgerhq.github.io/ledgerjs/docs>

**Tags:** electrum, bip32-hd-wallets, ledger-hardware-wallet


---

## 1 answers

### Answer by username_1 on 2019-03-18. Score: 2 | Accepted answer

A public key can have multiple addresses. It looks like what is happening here is that Electrum is creating a P2SH-P2WPKH type address while your NodeJS code is creating a P2PKH address. These are two different address types which have different spending requirements and transaction data. However Bitcoin sent to either address type can still be spent with the same private key and the same public key was used to create both addresses.

When you sent the Bitcoin to the P2PKH address, Electrum won't show it because it is not looking for Bitcoin sent to that address. Just because you have the private key necessary to spend some Bitcoin does not necessarily mean that your wallet will be looking for outputs of that kind. A wallet cannot track all possible output scripts that it can spend (it is infinite), it can only track the ones it is expecting to see. So for Electrum, it's only tracking the P2SH-P2WPKH address and not the P2PKH address that you sent Bitcoin to.

> **Comments:**
> **username_0**: I see, so the bitcoin address given by Ledger is indeed connected to my wallet, but it isn't tracked. Then I suppose I have to get both apps to either use P2PKH or P2SH-P2WPKH. After that I need to find some way to either track the address given by LedgerJS in the Electrum app... Or I need to get an address from Electrum and use it in LedgerJS. Either way you have my gratitude, your elaborate answer has helped me greatly.  

---

