Bitcoin

Error sending Bitcoin on testnet using Nbitcoin and QBitNinjaClient C#

I try too hard to send bitcoin on testnet. I tried to find some questions here.

My questions are:

Is QBitNinjaClient ready? Because I’ve seen that the parameter to getbalance end always throws 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