MetacoSA / NBitcoin

Comprehensive Bitcoin library for the .NET framework.
MIT License
1.88k stars 848 forks source link

Transaction Not Complete #221

Closed hitjariwala closed 7 years ago

hitjariwala commented 7 years ago

Hi,

I am develop webwallet using NBitcoin library. I am refer your book and make address, private key and scriptpubkey.

It require .NET code? Can you tell me what i use in new uint256(""). when i use my first transaction id it create new transactionid and hex but transaction not complete.

what is Node? How to create Node.

hitjariwala commented 7 years ago

I am complete one transaction using NBitcoin. Now it give new error when i spen 0.0001. ErrorCode: INSUFFICIENTFEE Error message: insufficient priority

Can any tell how to transfer fees to my address using NBitcoin.

NicolasDorier commented 7 years ago

You need to put more fees into your transaction, which, as my book says, is the difference between input and output.

hitjariwala commented 7 years ago

Hi,

Thanks for reply. Can you tell me which code best for Transaction?

  1. Transaction
  2. TransactionBuilder.
hitjariwala commented 7 years ago

Hi,

I am used this code it return success but not send bitcoin.

var txRepo = new NoSqlTransactionRepository(); //Let’s me introduce you, Alice, Bob, Satoshi, and Nico with their private keys. BitcoinSecret alice = new BitcoinSecret(""); BitcoinSecret satoshi = new BitcoinSecret("");

        var network = alice.Network;     

        Transaction aliceFunding = new Transaction()
        {
            Outputs =
                {
                    new TxOut("0.0009", alice.PrivateKey.PubKey)
                }
        };
        Coin[] aliceCoins = aliceFunding
                                .Outputs
                                .Select((o, i) => new Coin(new OutPoint(aliceFunding.GetHash(), i), o))
                                .ToArray();

        //Now Alice wants to send 1.00 BTC to Satoshi, with 0.001 BTC fees for miners.
        var txBuilder = new TransactionBuilder();
        var tx = txBuilder
            .AddCoins(aliceCoins)
            .AddKeys(alice.PrivateKey)
            .Send(satoshi.GetAddress(), "0.0002")
            .SendFees("0.0001")
            .SetChange(alice.GetAddress())
            .BuildTransaction(true);

        txRepo.Put(tx.GetHash(), tx);
        //Assert(txBuilder.Verify(tx)); //check fully signed
        Literal1.Text = tx.GetHash().ToString();

        var client = new QBitNinjaClient(network);
        BroadcastResponse broadcastResponse = client.Broadcast(tx).Result;

        if (!broadcastResponse.Success)
        {
            Literal1.Text = (string.Format("ErrorCode: {0}", broadcastResponse.Error.ErrorCode)).ToString();
            //Literal2.Text = ("Error message: " + broadcastResponse.Error.Reason).ToString();
        }
        else
        {
            Literal1.Text = ("Success! You can check out the hash of the transaciton in any block explorer:").ToString();
            //Literal2.Text = (transaction.GetHash()).ToString();
        }
NicolasDorier commented 7 years ago

please check https://www.gitbook.com/book/programmingblockchain/programmingblockchain/details there is a step by step way to send bitcoin. You do not have to use the txRepo. If it failed, you probably have either no enough fee, or spending a coin that has already been spent.

hitjariwala commented 7 years ago

i am see your book. it good

i am make first transaction using your code but cant make second transaction that why i use transactionbuilder. it return success but bitcoin not transfer to address.

please tell me if any issue in coding.

Thanks

NicolasDorier commented 7 years ago

give me your transaction in hex so I can check.

NicolasDorier commented 7 years ago

tx.ToHex()

hitjariwala commented 7 years ago

ToHex 0100000001951417e1940fc81b91ad02089ddb76d5f92f4626ccebf565c04692a7245809a4000000006a47304402206234099f86bde18d9e1ca284bbe3eedcd382c9855e9bdda7dcfe852758c3614d02200f04d98efd0df1627d0e7b822522a47b0e6c8922e40c3b0e22c51a0802c93f240121039445a6858efe7fe8c56850870664cb37e1150e9eeccb0dc2573d7f71c62bda4cffffffff0250c30000000000001976a914096c11b4e896001d5013e5e8c1b24d0db8a5bcf988ac307500000000000017a9142fe2e1e466414f27ff4c164296fa764238f9883b8700000000

Please also send me code for how to getbalance in this code. Transaction aliceFunding = new Transaction() { Outputs = { new TxOut("0.0009", alice.GetAddress()) } };

NicolasDorier commented 7 years ago

The input you are trying to spend does not exist in the blockchain a4095824a79246c065f5ebcc26462ff9d576db9d0802ad911bc80f94e1171495.

You can use

var coins = qbit.GetBalance(youaddress, true).Result.Operations.SelectMany(op => op.ReceivedCoins).ToArray();

to get the coins to spend.

hitjariwala commented 7 years ago

Thanks for fast reply.

Now code is working and completed transaction. check here https://www.smartbit.com.au/address/1rpYWDq48T84BzS2C5Hku8XA2htN57LAc

Now only one issue. How to spend transaction fees to my address?

hitjariwala commented 7 years ago

Hi,

It require generate wallet first?

NicolasDorier commented 7 years ago

You can't spend fee to your address, fees are for miners.

hitjariwala commented 7 years ago

Ok

I am create Webwallet Website. How to get transaction fees in Webwallet?

hitjariwala commented 7 years ago

Please check 1 day go and still transaction Unconfirm https://www.smartbit.com.au/tx/e84a0a0ed6b76450b1265eb9de0bf78fccbeb3d825b2b109753146331772a049

NicolasDorier commented 7 years ago

it is confirmed

NicolasDorier commented 7 years ago

your question make no sense, transaction fee does not go into a wallet, it goes to miners

hitjariwala commented 7 years ago

Ok

but it Confirm after 1 days.

NicolasDorier commented 7 years ago

put more fee next time

hitjariwala commented 7 years ago

I sent 0.0001 transaction fees. How to calculate fees?

NicolasDorier commented 7 years ago

some website can tell you like https://bitcoinfees.21.co/ or use bitcoind estimatefee rpc command.

hitjariwala commented 7 years ago

Can you tell me which API Best for Create Webwallet?

NicolasDorier commented 7 years ago

Yes. Do not create web wallets. And do not use third party API. Learn more about bitcoin before starting, your questions show lots of incomprehension yet. My book is a start, but search also other resources.

hitjariwala commented 7 years ago

Now i am use Bitgo API for create Webwallet.

NicolasDorier commented 7 years ago

Bitgo is reasonable. Never used it though.

hitjariwala commented 7 years ago

Please guide me which is best for create webwallet.

Please Skype hit.jariwala

NicolasDorier commented 7 years ago

sorry I don't have time to help you, read the documentation of bitgo.