<p>Thanks everyone for the explanation. So yes, only a private key can be enough to generate a bech32 address. The issue in my case seems to be that I was using</p>
<p><code>var addr = key1.ScriptPubKey.GetWitScriptAddress(net); </code></p>
<p>Instead of</p>
<p><code>Key key1 = new Key();</code></p>
<p><code>var secret = new BitcoinSecret(key1, net);</code></p>
<p><code>var addr = secret.GetAddress(ScriptPubKeyType.Segwit); </code></p>
<p>Now the output addresses of mycelium and my program match.</p>

CC BY-SA 4.0
2020-11-02T10:17:43.840Z
2020-11-02T10:17:43.840Z
Relaxo143
<p>So I wrote a vanity address generator in c# with the NBitcoin lib. When I use the private key used to generate the address and input it in Mycelium it outputs a different address. This does not occur when working with legacy addresses, so I'm guessing I need something more than just a private key in order to generate a segwit address. Was it a redeem script or something? How can I make sure I get the same address in a wallet when I input the privkey?</p>

CC BY-SA 4.0
2020-11-01T22:50:03.863Z
For a typical single key segwit address (P2WPKH), it is just a key. How are you creating the address? Can you give an example of the key you use, the address Mycelium creates, and the address that you create?
Ava Chow
CC BY-SA 4.0
2020-11-01T23:44:43.360Z
My program outputs: Address: bc1q00dnht0ymgkxp8cxlcg5e7mty0w3w9mnvt49vkn75hc809t7nmrq5g9djj
Private Key: KyaVpeyGfVRgWUtY2t9HYa7rssFkEcWeE53rNudbEAVRdg3EPpQs                  while Mycelium outputs bc1qa59kdryyyh43gyekxswjj3dwsrzs273rs97puv                                        how do I make new lines without submitting the comment?
Relaxo143
CC BY-SA 4.0
2020-11-02T01:23:38.163Z
You can edit your question with the additional information.
Ava Chow
<address-generation><bech32-address><c#><nbitcoin>
What is needed to generate a bech32 address?
Relaxo143
# What is needed to generate a bech32 address?

(Asked by: username_0 on 2020-11-01)

So I wrote a vanity address generator in c# with the NBitcoin lib. When I use the private key used to generate the address and input it in Mycelium it outputs a different address. This does not occur when working with legacy addresses, so I'm guessing I need something more than just a private key in order to generate a segwit address. Was it a redeem script or something? How can I make sure I get the same address in a wallet when I input the privkey?

**Tags:** address-generation, bech32-address, c#, nbitcoin

> **Comments:**
> **username_1**: For a typical single key segwit address (P2WPKH), it is just a key. How are you creating the address? Can you give an example of the key you use, the address Mycelium creates, and the address that you create?  
> **username_0**: My program outputs: Address: bc1q00dnht0ymgkxp8cxlcg5e7mty0w3w9mnvt49vkn75hc809t7nmrq5g9djj Private Key: KyaVpeyGfVRgWUtY2t9HYa7rssFkEcWeE53rNudbEAVRdg3EPpQs                  while Mycelium outputs bc1qa59kdryyyh43gyekxswjj3dwsrzs273rs97puv                                        how do I make new lines without submitting the comment?  
> **username_1**: You can edit your question with the additional information.  

---

## 1 answers

### Answer by username_0 on 2020-11-02. Score: 0

Thanks everyone for the explanation. So yes, only a private key can be enough to generate a bech32 address. The issue in my case seems to be that I was using

`var addr = key1.ScriptPubKey.GetWitScriptAddress(net);`

Instead of

`Key key1 = new Key();`

`var secret = new BitcoinSecret(key1, net);`

`var addr = secret.GetAddress(ScriptPubKeyType.Segwit);`

Now the output addresses of mycelium and my program match.


---

