1

I'm trying to build a transaction using Nbitcoin. When I run this line there is an error parsing the address. It runs fine with segwit addresses starting with a 1, but not native segwit.

Using System;
Using System.Text;
Using NBitcoin;

static void Main(string[] args) {

    var wallet = new BitcoinPubKeyAddress("bc1q....", Network.Main); //throws error
}

Error: System.FormatException: 'Invalid base58 data'

Is there a way to use native segwit with Nbitcoin? Thanks

1 Answer 1

1

It runs fine with segwit addresses starting with a 1, but not native segwit.

Prefix 1 is used by legacy addresses. You can check the other prefixes used here: https://en.bitcoin.it/wiki/List_of_address_prefixes

Is there a way to use native segwit with Nbitcoin?

Replace BitcoinPubKeyAddress with BitcoinWitPubKeyAddress in your code for using native segwit addresses

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.