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?

3
  • 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
    Commented Nov 1, 2020 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
    Commented Nov 1, 2020 at 23:44
  • You can edit your question with the additional information.
    – Ava Chow
    Commented Nov 2, 2020 at 1:23

2 Answers 2

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

1
  • 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
    Commented Nov 18, 2020 at 0: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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.