How to get/understand Bitcoin Transaction ID

1.1k views Asked by At

i am using c# and NBitcoin to write my own Programm. (Reading the Book "Programming Blockchain") I can send out Bitcoins just fine, but very complicated. This is due to my lack of understanding of the Transaction ID.

At the moment i need to get the last Transaction ID from my Bitcoin. And with the help of this ID i can than send this Bitcoin somewhere else.

This is also my main Problem. Do i have to save every transaction id of every BItcoin i ever recieved? In this sentence i use "Bitcoin" to represent any amount of Bitcoin. What if i have an address where i recieved 2 Bitcoins (1+1) and i want to spend 1.5 BItcoin now? If i spent one "complete" coin i can forget the transaction ID and only have to keep the one of the remaining half?

An example to make express my confusion more clearly: I have an Address (ABCDEFGH) and i recieved 10 Bitcoins with 10 different transactions (Transaction ID 1-10) Since i was not involved in the sending (somone people gifted it to me) i do not know the transaction IDs of those 10 Transactions. How do i get them programmatically? After getting all the TransactionIDs, do i have to write them now all down and keep track of them for my ABCDEFGH address for future spendings or is there some way to just say "spend x amount of of this address"?

From the book i somehow had the understanding that i need to spend always 1 Bitcoin per transaction. So if i want to send 0.3 Bitcoin i have to send 0.3 Bitcoin to the reciever and 0.7 back to me?!?!

Is there a way to Programm it like this:

Transaction(MoneyAmount,RecieverAddress,SenderAddress);

1

There are 1 answers

1
Klark On

I think i found a way to do this but a last bit of C# Wisdom is missing:

var balance = client.GetBalance(new BitcoinPubKeyAddress(bitcoinPrivateKey.GetAddress().ToString())).Result;

var tid = new List<String>();
foreach (var operation in balance.Operations)
                //Console.WriteLine(operation.TransactionId.ToString());
                tid.AddRange(operation.TransactionId.ToString());

If i use the Console.WriteLine i get the correct transaction IDs. But for some reason i cannot add the TransactionID strings to the List. It says it cannot convert "string" to System.Collections.Generic.IEnumerable