~ The Anatomy of a Bitcoin Transaction ~

TXID, Outputs, Inputs, Transaction Fees, UTXOs - what do all these terms mean?

In this thread we will dissect a real bitcoin transaction and I'll explain its main components

To expand your background knowledge, read on 👇
The top of the page has a bunch of data about the Block it was mined in, the fees paid, and some other stuff, but let's focus on the bottom part of the page, as shown in this screenshot:
The first part you should know about is the Transaction ID, also known as the TXID (circled in red).

This is used to uniquely identify a transaction, and it comes from taking the SHA-256 Hash of the transaction data twice.
(Side note, for a primer on what a SHA-256 Hash is, check out my thread on Hash functions) https://twitter.com/dannydiekroeger/status/1281100866871648256?s=20
Next lets look at those two entries on the right. These are the Outputs (recipients) of the transaction

The recipients are identified by those jumble of numbers and letters that start with a 3.

These are bitcoin addresses, and you can think of them kinda like email addresses
In software, it's common to count starting from 0, which is why the first Output is labeled as #0, and the second is labeled as #1
Ok so we've identified the TXID and the Outputs, now lets take a look at the Input to this transaction, which is on the left.

Transactions can have multiple inputs, but this transaction has just one single Input, worth 0.69561192 BTC.
Now that we've inspected the TXID, the Outputs, and the Input, let's take a step back a summarize what's happening in this transaction.

Somebody spent 0.69561192 BTC

One address received 0.2862 BTC
Another address received 0.40861192 BTC
If you're quick at Math, you might realize that the amount Spent is slightly larger than the total amount Received...

0.69561192 - (0.2862 + 0.40861192) = 0.0008

Hmm.. what happened here, was it a mistake?
This missing amount is actually not a mistake at all

This leftover amount is what's known as the Transaction Fee, and it's a bribe paid to the miners to convince them to mine (finalize) the transaction

Higher fee rate = higher incentive for a miner to finalize your transaction
The fee is never explicitly written into the transaction

It's just calculated by subtracting the outputs from the inputs

The miner who mines a block with this transaction gets to claim these fees as their own

The website has calculated this fee for us and shows it at the top
Ok so we've covered the TXID, Outputs, Inputs, and Transaction Fees.

But let's dive a little further and explain where that Input came from.

You see, when an Output is created, it becomes what we call a UTXO (or Unspent Transaction Output)
You can think of UTXOs like the dollar bills and coins in your physical wallet

These are the funds you have available to Spend at any given moment

To spend a UTXO, you put it as an Input to a transaction.
Let's see if we can figure out where our Input came from.

If we take another look, we'll see the Input has an identifier on it that looks like a TXID with ":1" added to the end
This identifier (txid + :number) has a few different names, some call it a "UTXO-key", or an "outpoint".

In our situation it tells us our Input comes from Output #1 of 72a3393bd12a97daae13e1f2a7838a235e8dcf1de7845528afae74e999adaa66
So let's click on that link and see where it takes us!

It takes us to a previous transaction...

Now take a look at the second Output (Output #1) of this previous transaction...

Do you notice anything?
Look at the amount, it is 0.69561192 BTC, which is exactly the same amount as the Input to our original transaction!
You've just done what every bitcoin node does for every transaction before accepting it - you've validated that it is spending the correct amount from a previous output. Nice!

Here's a graphic showing the two transactions - the older one on top, and the newer one on the bottom
This linking of outputs to inputs is how the network monitors the history of all transactions, and ensures that no unexpected new coins are created.

Each output can only be spent once!
Make sense? Awesome!

But here's a question for you...

Say I only own a single UTXO, worth 0.69561192 BTC, but I want to send my friend @SahilBloom 0.2862 BTC?
Well let's go back to the dollar bill analogy and ask the same question.

Imagine I have a single 10 dollar bill in my wallet, but I want to buy a 5 dollar coffee?

Easy, I give the cashier my 10 dollar bill, and they give me back a 5 dollar bill as Change.
Bitcoin uses a similar concept of Change.

For me to pay @SahilBloom 0.2862 using my 0.69561192 UTXO, I'll create a transaction with two Outputs:

One for 0.2862 to Sahil

And one that gives the remaining 0.40861192 change back to me
Looks like that's exactly what might have happened in this transaction we dissected!

Although this wasn't actually my transaction - so I can't say for sure which output was the payment and which was the change, but you get the idea.
So let's recap:

We learned about TXIDs, Outputs, Inputs, Fees, UTXOs, Change, and the basic concept of how transactions are linked (Outputs are UTXOs until they become Inputs).
There's a lot more we can discuss regarding Transactions, but I'll end the thread here.

I hope this was a helpful summary of the basics. Let me know in the comments if you have any questions!
Just posted a new one on Transaction Fees https://twitter.com/dannydiekroeger/status/1282189867770765313?s=21
You can follow @dannydiekroeger.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled:

By continuing to use the site, you are consenting to the use of cookies as explained in our Cookie Policy to improve your experience.