<p>Question was <a href="https://github.com/MetacoSA/NBitcoin/issues/1034" rel="nofollow noreferrer">posted &amp; answered on the NBitcoin repo</a>, so copying my answers here for the benefit of SE members:</p>
<blockquote>
<p>This is a Blockchain.com-specific UX issue... They technically could generate a Segwit address, but they default to <code>P2PKH</code> (legacy) at the moment.</p>
<p><code>WIF</code> is an old format that doesn't carry metadata about the kind of address that should be unwrapped from the private key, so when you import a private key <code>WIF</code> into a wallet, it's up to the wallet to decide what kind of address to give you for that private key.</p>
<p>ps: Some wallets are &quot;smart&quot; and check all possible addresses (Legacy, Segwit, SegwitP2SH, ...) and then pick whichever one has a balance, so you might want to put some satoshis on the Segwit address that you create <em>before</em> importing the private key <code>WIF</code> to a wallet.</p>
</blockquote>
<hr />
<blockquote>
<p>Private keys can be associated with public keys that are either compressed (<code>33</code> bytes) or uncompressed (<code>65</code> bytes), and the <code>WIF</code> will be different if compressed/uncompressed. For instance, compressed public keys start with <code>L</code> or <code>K</code> on Mainnet and <code>c</code> on Testnet, whilst uncompressed public keys start with <code>5</code> on Mainnet and <code>9</code> on Testnet.</p>
<p>You can modify your code sample above to use uncompressed public keys (the default is compressed):</p>
<pre><code>var key = new Key(fCompressedIn: false);
// ...
</code></pre>
</blockquote>
<hr />

CC BY-SA 4.0
2021-08-03T20:13:39.423Z
2021-08-03T20:13:39.423Z
C. Augusto Proiete
<p>I'm trying to generate a public address and for that, I have the code:</p>
<pre><code>var key = new Key();
var wif = key.GetWif(Network.Main);

Console.WriteLine($&quot;WIF: {wif}&quot;);

var secret = new BitcoinSecret(key, Network.Main);
Console.WriteLine($&quot;Private Key: {secret.ToWif()}&quot;);
Console.WriteLine($&quot;Public Address (Legacy): {secret.GetAddress(ScriptPubKeyType.Legacy)}&quot;);
Console.WriteLine($&quot;Public Address (Segwit): {secret.GetAddress(ScriptPubKeyType.Segwit)}&quot;);
Console.WriteLine($&quot;Public Address (SegwitP2SH): {secret.GetAddress(ScriptPubKeyType.SegwitP2SH)}&quot;);
</code></pre>
<p>When I pick the WIF and import it to Blockchain.com (for example), I only get the Legacy public address. Can the same private key sign Segwit and SegwitP2SH transactions?
How can I import a private key and get the Segwit and SegwitP2SH public addresses?</p>
<p>My knowledge about how this works is limited and I'm trying to learn...</p>

<blockchain.info><c#><nbitcoin>
Generate public addresses (NBitcoin)
Paulo Aboim Pinto
# Generate public addresses (NBitcoin)

(Asked by: username_0 on 2021-07-21)

I'm trying to generate a public address and for that, I have the code:
var key = new Key();
var wif = key.GetWif(Network.Main);

Console.WriteLine($"WIF: {wif}");

var secret = new BitcoinSecret(key, Network.Main);
Console.WriteLine($"Private Key: {secret.ToWif()}");
Console.WriteLine($"Public Address (Legacy): {secret.GetAddress(ScriptPubKeyType.Legacy)}");
Console.WriteLine($"Public Address (Segwit): {secret.GetAddress(ScriptPubKeyType.Segwit)}");
Console.WriteLine($"Public Address (SegwitP2SH): {secret.GetAddress(ScriptPubKeyType.SegwitP2SH)}");

When I pick the WIF and import it to Blockchain.com (for example), I only get the Legacy public address. Can the same private key sign Segwit and SegwitP2SH transactions?
How can I import a private key and get the Segwit and SegwitP2SH public addresses?
My knowledge about how this works is limited and I'm trying to learn...

**Tags:** blockchain.info, c#, nbitcoin


---

## 1 answers

### Answer by username_1 on 2021-08-03. Score: 1

Question was posted & answered on the NBitcoin repo, so copying my answers here for the benefit of SE members:

This is a Blockchain.com-specific UX issue... They technically could generate a Segwit address, but they default to P2PKH (legacy) at the moment.
WIF is an old format that doesn't carry metadata about the kind of address that should be unwrapped from the private key, so when you import a private key WIF into a wallet, it's up to the wallet to decide what kind of address to give you for that private key.
ps: Some wallets are "smart" and check all possible addresses (Legacy, Segwit, SegwitP2SH, ...) and then pick whichever one has a balance, so you might want to put some satoshis on the Segwit address that you create before importing the private key WIF to a wallet.



Private keys can be associated with public keys that are either compressed (33 bytes) or uncompressed (65 bytes), and the WIF will be different if compressed/uncompressed. For instance, compressed public keys start with L or K on Mainnet and c on Testnet, whilst uncompressed public keys start with 5 on Mainnet and 9 on Testnet.
You can modify your code sample above to use uncompressed public keys (the default is compressed):
var key = new Key(fCompressedIn: false);
// ...


---

