2

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?

Relaxo143
  • 21
  • 2
  • 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? – Andrew Chow Nov 01 '20 at 22:50
  • My program outputs: Address: bc1q00dnht0ymgkxp8cxlcg5e7mty0w3w9mnvt49vkn75hc809t7nmrq5g9djj Private Key: KyaVpeyGfVRgWUtY2t9HYa7rssFkEcWeE53rNudbEAVRdg3EPpQs while Mycelium outputs bc1qa59kdryyyh43gyekxswjj3dwsrzs273rs97puv how do I make new lines without submitting the comment? – Relaxo143 Nov 01 '20 at 23:44
  • You can edit your question with the additional information. – Andrew Chow Nov 02 '20 at 01:23

2 Answers2

1
            var bitcoinPrivateKey = new BitcoinSecret("cPof7e5g6xfgB6AZrc6XVTVwA4efLJurh9kVxa6FRChbr8Jyqaon", Network.TestNet);

            var legacy_address = bitcoinPrivateKey.GetAddress(ScriptPubKeyType.Legacy);
            var segwitp2sh_address = bitcoinPrivateKey.GetAddress(ScriptPubKeyType.SegwitP2SH);
            var nativesegwit_address = bitcoinPrivateKey.GetAddress(ScriptPubKeyType.Segwit);

            Console.WriteLine("Private Key :" + bitcoinPrivateKey);
            Console.WriteLine("Legacy Address :" + legacy_address);
            Console.WriteLine("Segwit-P2SH Address :" + segwitp2sh_address);
            Console.WriteLine("Bech32 Address :" + nativesegwit_address);

output

Mycelium testnet bitcoin wallet:

mycelium

  • how are you generating *var bitcoinPrivateKey*. For example if I wanted to create a bech32 brainwallet from the value "TheEarthIsFlatl" how would you do that? The private key would be Kx9M5DcnWdcsfhtQdZyQVLa265EtTt2T2HTSwhHhhf5e16JhZWui and the public address would be bc1q856phefcga58hcmd0et2mx78v6q54egj2ulhfl – vvvv4d Nov 18 '20 at 00:06
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.

Relaxo143
  • 21
  • 2