<p>Yes. You can get the public key, chaincode, and address for any derivation path.</p>

<p>If you use the <a href="https://github.com/LedgerHQ/btchip-python" rel="nofollow noreferrer"><code>btchip-python</code></a> library, you can use the <code>getWalletPublicKey()</code> method to retrieve a dictionary containing all three of those things.</p>

CC BY-SA 4.0
2019-02-12T19:34:53.980Z
Hey, thanks for the response. How to I get python to interact with the ledger device?
Ppeters62
CC BY-SA 4.0
2019-02-12T21:11:02.493Z
You need to use `getDongle` from https://github.com/LedgerHQ/btchip-python/blob/master/btchip/btchipComm.py to get the device object to do the calls with. Alternatively you can use the HWI project (https://github.com/bitcoin-core/HWI) to get an xpub from your Ledger and extract the chaincode from that. HWI is a python library and command line tool to do stuff with hardware wallets.
Ava Chow
CC BY-SA 4.0
2019-02-12T18:21:14.057Z
2019-02-12T18:21:14.057Z
Ava Chow
<p>Extracting BIP 32/39/44 chain code is agnostic as to whether a Ledger device or Trezor device is used. Remember the chain code is based upon open standards, specifally see <a href="https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#serialization-format" rel="nofollow noreferrer">https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#serialization-format</a>.</p>

<p>Here is how chain code can be found for the Bitcoin path m/44'/0'/0'/0 for the example at <a href="https://github.com/libbitcoin/libbitcoin-system/wiki/Altcoin-Version-Mappings#7-bitcoin-btc-bip-3944-technology-examples" rel="nofollow noreferrer">https://github.com/libbitcoin/libbitcoin-system/wiki/Altcoin-Version-Mappings#7-bitcoin-btc-bip-3944-technology-examples</a>:</p>

<p><strong>This is the level the chain code was determined for below:</strong></p>

<p>% echo "radar blur cabbage chef fix engine embark joy scheme fiction master release" | bx mnemonic-to-seed | bx hd-new | bx hd-private -d -i 44 | bx hd-private -d -i 0 | bx hd-private -d -i 0 | bx hd-private -i 0 | bx base58-decode | cut -c 9-10</p>

<p><code>04</code></p>

<p><strong>This is the index the chain code was determined for below:</strong></p>

<p>% echo "radar blur cabbage chef fix engine embark joy scheme fiction master release" | bx mnemonic-to-seed | bx hd-new | bx hd-private -d -i 44 | bx hd-private -d -i 0 | bx hd-private -d -i 0 | bx hd-private -i 0 | bx base58-decode | cut -c 19-26</p>

<p><code>00000000</code></p>

<p><strong>This is the chain code for the particular level and index:</strong></p>

<p>% echo "radar blur cabbage chef fix engine embark joy scheme fiction master release" | bx mnemonic-to-seed | bx hd-new | bx hd-private -d -i 44 | bx hd-private -d -i 0 | bx hd-private -d -i 0 | bx hd-private -i 0 | bx base58-decode | cut -c 27-90</p>

<p><code>6fbe96de86322b27a540572e2777562f55fb9810327917f9dd1163592952272a</code></p>

<p><strong>This is the associated secp256k1 private key:</strong></p>

<p>% echo "radar blur cabbage chef fix engine embark joy scheme fiction master release" | bx mnemonic-to-seed | bx hd-new | bx hd-private -d -i 44 | bx hd-private -d -i 0 | bx hd-private -d -i 0 | bx hd-private -i 0 | bx base58-decode | cut -c 93-156</p>

<p><code>c227b3ba34eecfee2830b06bef3b35d5a88d4f6a9c5f34bd3d4e465e6c3ead1f</code></p>

CC BY-SA 4.0
2019-03-15T01:12:18.447Z
2019-03-15T01:12:18.447Z
skaht
<p>The question is basically in the title. Can I (or it is possible to) extract the chain code from a ledger nano s device? It doesn't have to be the Master Chain Code. Any of them will do.</p>

<ledger-hardware-wallet>
Chain Code from Ledger Nano S
Ppeters62
# Chain Code from Ledger Nano S

(Asked by: username_0 on 2019-02-12)

The question is basically in the title. Can I (or it is possible to) extract the chain code from a ledger nano s device? It doesn't have to be the Master Chain Code. Any of them will do.

**Tags:** ledger-hardware-wallet


---

## 2 answers

### Answer by username_1 on 2019-02-12. Score: 1

Yes. You can get the public key, chaincode, and address for any derivation path.

If you use the [`btchip-python`](https://github.com/LedgerHQ/btchip-python) library, you can use the `getWalletPublicKey()` method to retrieve a dictionary containing all three of those things.

> **Comments:**
> **username_0**: Hey, thanks for the response. How to I get python to interact with the ledger device?  
> **username_1**: You need to use `getDongle` from https://github.com/LedgerHQ/btchip-python/blob/master/btchip/btchipComm.py to get the device object to do the calls with. Alternatively you can use the HWI project (https://github.com/bitcoin-core/HWI) to get an xpub from your Ledger and extract the chaincode from that. HWI is a python library and command line tool to do stuff with hardware wallets.  

---

### Answer by username_2 on 2019-03-15. Score: 0

Extracting BIP 32/39/44 chain code is agnostic as to whether a Ledger device or Trezor device is used. Remember the chain code is based upon open standards, specifally see <https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#serialization-format>.

Here is how chain code can be found for the Bitcoin path m/44'/0'/0'/0 for the example at <https://github.com/libbitcoin/libbitcoin-system/wiki/Altcoin-Version-Mappings#7-bitcoin-btc-bip-3944-technology-examples>:

**This is the level the chain code was determined for below:**

% echo "radar blur cabbage chef fix engine embark joy scheme fiction master release" | bx mnemonic-to-seed | bx hd-new | bx hd-private -d -i 44 | bx hd-private -d -i 0 | bx hd-private -d -i 0 | bx hd-private -i 0 | bx base58-decode | cut -c 9-10

`04`

**This is the index the chain code was determined for below:**

% echo "radar blur cabbage chef fix engine embark joy scheme fiction master release" | bx mnemonic-to-seed | bx hd-new | bx hd-private -d -i 44 | bx hd-private -d -i 0 | bx hd-private -d -i 0 | bx hd-private -i 0 | bx base58-decode | cut -c 19-26

`00000000`

**This is the chain code for the particular level and index:**

% echo "radar blur cabbage chef fix engine embark joy scheme fiction master release" | bx mnemonic-to-seed | bx hd-new | bx hd-private -d -i 44 | bx hd-private -d -i 0 | bx hd-private -d -i 0 | bx hd-private -i 0 | bx base58-decode | cut -c 27-90

`6fbe96de86322b27a540572e2777562f55fb9810327917f9dd1163592952272a`

**This is the associated secp256k1 private key:**

% echo "radar blur cabbage chef fix engine embark joy scheme fiction master release" | bx mnemonic-to-seed | bx hd-new | bx hd-private -d -i 44 | bx hd-private -d -i 0 | bx hd-private -d -i 0 | bx hd-private -i 0 | bx base58-decode | cut -c 93-156

`c227b3ba34eecfee2830b06bef3b35d5a88d4f6a9c5f34bd3d4e465e6c3ead1f`


---

