MetacoSA / QBitNinja

An Open Source and powerful blockchain API
MIT License
68 stars 42 forks source link

Unable to Broadcast Transaction For Second Time #124

Closed yogeshgautam48 closed 3 years ago

yogeshgautam48 commented 3 years ago

I am trying to send bitcoin from my address to another address using NBitcoin and QBitNinja i had 0.0024BTC in my wallet and then i performed a transfer using this article:

https://programmingblockchain.gitbook.io/programmingblockchain/bitcoin_transfer/spend_your_coin#sign-your-transaction

The Transfer was success. I was happy.

Now i again tried to perform another transaction. Since i still have unspent amount in that transactionId so i used the same TransactionId this time as well.

        var client = new QBitNinjaClient(network);
        var transactionId = uint256.Parse("975304016bdbb6855e662d25570ebab9233a5b78fbebee0f7f34104c5c197ee6");
        var transactionResponse = client.GetTransaction(transactionId).Result;

I got success response along with hash in the code but when i went to explorer i cannot find another transaction there is only one transaction.

NicolasDorier commented 3 years ago

it might be because it was to low fee? btw now qbitninja may be down, as I am transferring the domain name to another registar.

yogeshgautam48 commented 3 years ago

Thankyou for your comment. I solved this issue now. Basically it was regarding getting coins.

Previously what i had done was:

    var client = new QBitNinjaClient(network);
    var transactionId = uint256.Parse("975304016bdbb6855e662d25570ebab9233a5b78fbebee0f7f34104c5c197ee6");
    var transactionResponse = client.GetTransaction(transactionId).Result;
    var coins=transactionResponse.ReceivedCoins; //This didn't worked the second time even though i have balance

But simply

     var coins = client.GetBalance(bitcoinPrivateKey.GetAddress(), true).Result.Operations.SelectMany(op => op.ReceivedCoins).ToArray();  //This works