Bitcoin

Error sending Bitcoin on testnet using Nbitcoin and QBitNinjaClient C#

I’m trying to send Bitcoin through testnet.

I’ve looked at the questions on this site, but they seem old.

Is QBitNinjaClient working? getbalance It always returns an error.

Newtonsoft.Json.JsonReaderException: ‘An unexpected character occurred while parsing the value: <. path '', line 0, position 0.'

var fpk = new BitcoinSecret("cVDNzGDRPxQ6vkQ9VJcJpLKhuvFRQMYEaMegEw9hK5z5ZttkSut2", Network.TestNet);
var fspk = fpk.GetAddress(ScriptPubKeyType.Legacy);
var api = new QBitNinjaClient("http://tapi.qbit.ninja/", fpk.Network);
var fbal = await api.GetBalance(fspk, true);
var fcoin = new List<ICoin>();
foreach (var o in fbal.Operations)

    if (o.Confirmations < 2) continue; // 2 confirmations
    fcoin.AddRange(o.ReceivedCoins);


var builder = fpk.Network.CreateTransactionBuilder();
var tx = builder
    .AddCoins(fcoin)
    .AddKeys(new ISecret()  fpk )
    .Send(new BitcoinPubKeyAddress("myUo9SDsAZKVfnYdJgbVvXcmCFVL7Adxi9", fpk.Network), Money.Coins(0.001m))
    .SubtractFees()
    .SendFees(Money.Coins(0.00001m))
    .SetChange(fpk)
    .BuildTransaction(true);

Debug.Assert(builder.Verify(tx));
var r = await api.Broadcast(tx);

Related Articles

Back to top button