<p>I solved this with a pull request that adds a property to <code>ExtKey</code> and <code>ExtPubKey</code> that allows you to call the <code>ChainCode</code> property. See <a href="https://github.com/MetacoSA/NBitcoin/pull/156" rel="nofollow">pull request 156</a>.</p>

<p>It has been merged into <a href="https://www.nuget.org/packages/NBitcoin/" rel="nofollow">NBitcoin 3.0.0.28 which is available on NuGet</a>.</p>

CC BY-SA 3.0
2016-05-22T18:35:15.720Z
2016-05-22T18:35:15.720Z
Leon Cullens
<p>Here are a few things what you can do, I noted what you need in comment:  </p>

<pre><code>var masterPrivateKey = new ExtKey();
var masterPublicKey = masterPrivateKey.Neuter();

// This is what you need:
var masterMainNetPrivateKey = masterPrivateKey.GetWif(Network.Main);
var masterTestNetPrivateKey = masterPrivateKey.GetWif(Network.TestNet);

var masterMainNetPublicKey = masterPublicKey.GetWif(Network.Main);
var masterTestNetPublicKey = masterPublicKey.GetWif(Network.TestNet);
</code></pre>

<p>You might want to check the <a href="https://programmingblockchain.gitbooks.io/programmingblockchain/content/key_storage_and_generation/key_generation.html" rel="nofollow">corresponding section of the C# Bitcoin book</a>.  </p>

CC BY-SA 3.0
2016-05-22T18:31:38.983Z
No, that's not what I need. WIF and Chain Code are two completely different things. WIF is just a way to encode a private key.
Leon Cullens
CC BY-SA 3.0
2016-05-22T18:32:58.303Z
Anyway, I added a change to NBitcoin that exposes the chain code through a property, see PR 156 https://github.com/MetacoSA/NBitcoin/pull/156. It has been merged into NBitcoin 3.0.0.28, available on NuGet.
Leon Cullens
CC BY-SA 3.0
2016-05-22T17:24:48.340Z
2016-05-22T17:24:48.340Z
nopara73
<p>I'm using NBitcoin and I created an <code>ExtKey</code> object. Now I need to get the Master Chain Code (see page 89 of Mastering Bitcoin for a good explanation) for this HD node. How do I do this?</p>

<p>According to Mastering Bitcoin a root seed is used with HMAC-SHA512 to create a 512-bits output. The left 256 bits are used for the master private key, the right 256 bits are used for the master chain code. When I call <code>GetBytes()</code> on my <code>ExtKey</code> object, however, it returns a byte[74] array. This corresponds to 592 bits. I don't know what the extra 80 bits are so I can't just take the right 256 bits.</p>

<bip32-hd-wallets><nbitcoin>
How to get Master Chain Code
Leon Cullens
# How to get Master Chain Code

(Asked by: username_0 on 2016-04-28)

I'm using NBitcoin and I created an `ExtKey` object. Now I need to get the Master Chain Code (see page 89 of Mastering Bitcoin for a good explanation) for this HD node. How do I do this?

According to Mastering Bitcoin a root seed is used with HMAC-SHA512 to create a 512-bits output. The left 256 bits are used for the master private key, the right 256 bits are used for the master chain code. When I call `GetBytes()` on my `ExtKey` object, however, it returns a byte[74] array. This corresponds to 592 bits. I don't know what the extra 80 bits are so I can't just take the right 256 bits.

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


---

## 2 answers

### Answer by username_0 on 2016-05-22. Score: 0 | Accepted answer

I solved this with a pull request that adds a property to `ExtKey` and `ExtPubKey` that allows you to call the `ChainCode` property. See [pull request 156](https://github.com/MetacoSA/NBitcoin/pull/156).

It has been merged into [NBitcoin 3.0.0.28 which is available on NuGet](https://www.nuget.org/packages/NBitcoin/).


---

### Answer by username_1 on 2016-05-22. Score: -1

Here are a few things what you can do, I noted what you need in comment:  
var masterPrivateKey = new ExtKey();
var masterPublicKey = masterPrivateKey.Neuter();

// This is what you need:
var masterMainNetPrivateKey = masterPrivateKey.GetWif(Network.Main);
var masterTestNetPrivateKey = masterPrivateKey.GetWif(Network.TestNet);

var masterMainNetPublicKey = masterPublicKey.GetWif(Network.Main);
var masterTestNetPublicKey = masterPublicKey.GetWif(Network.TestNet);

You might want to check the corresponding section of the C# Bitcoin book.

> **Comments:**
> **username_0**: No, that's not what I need. WIF and Chain Code are two completely different things. WIF is just a way to encode a private key.  
> **username_0**: Anyway, I added a change to NBitcoin that exposes the chain code through a property, see PR 156 https://github.com/MetacoSA/NBitcoin/pull/156. It has been merged into NBitcoin 3.0.0.28, available on NuGet.  

---

