EVG101 Part 3: Bitcoin Transactions

Everest Ventures Group
EVG101
Published in
8 min readMar 25, 2019

Welcome to Part 3 of Everest’s crypto and blockchain guide! In this article, we go into the details of how transactions in Bitcoin work. As we will see, Bitcoin transactions work slightly differently to transactions in the real world.

To go back to our home page: link

To go back to the previous article on the people behind Bitcoin: link

To go to the next article on mining in Bitcoin: link

Table of Contents

  1. How do transactions usually work?
  2. What is UTXO (unspent transaction output)?
  3. How do transactions in Bitcoin work exactly?
  4. Can I have an example of a Bitcoin transaction?
  5. How does one broadcast transactions to other nodes?
  6. How many transactions can each Bitcoin block have?

TLDR;

A summary of Part 3 of our guide

1. How do transactions usually work?

Most of the time when we speak of transactions, we are used to an account/balance system. This means that every user in the system has an account, and every account is associated with a balance which determines how much money or points that account possesses.

Account balances are updated when one user in the system makes a transaction by sending money to another user in the system. For example, if A originally has 10 bitcoin, and B has 5 bitcoin, if A makes a transaction by sending 2 bitcoin to B, A ends up with 10–2=8 bitcoin and B ends up with 5+2=7 bitcoin.

How transactions work in the account/balance system

2. What is UTXO (unspent transaction output)?

Bitcoin uses a UTXO (unspent transaction output) model instead of an account/balance system. This means that the blockchain does not directly keep track of each Bitcoin address’ balance of Bitcoin. Instead, the blockchain keeps a record of every single Bitcoin transaction ever made, whereas the Bitcoin network keeps track of the set of all UTXOs, known as the mempool or the transaction pool, in the network. The balance of a particular Bitcoin address is calculated by checking for and summing all UTXOs associated with that address. When a UTXO is spent, it is removed from the transaction pool. This expenditure is reflected when the new balance is calculated by summing the remaining UTXOs.

In Bitcoin, a UTXO is a discrete unit of Bitcoin which can contain a fixed, immutable value of any amount. One UTXO can represent 0.1 bitcoin, 1 bitcoin, or even 100 bitcoins. Regardless of the magnitude of the value itself, this value is associated with a unique UTXO which can be identified by its id. Each UTXO, by definition, is the result of an output from a transaction and is associated with a specific Bitcoin address.

To see how this works, consider a world where there are only 3 people, A, B, and C. The transaction pool contains only UTXOs that belong to either A, B, or C. To calculate the balance for one of them, say A, we look at all the UTXOs belonging to A and sum them up: 1 + 3 + 1.2 = 5.2 BTC. This is illustrated below in the visual.

A visual to illustrate how balances are calculated in a UTXO system vs an account/balance system

The fundamental property of UTXOs is that they cannot be broken down — you cannot convert a UTXO into two or more smaller UTXOs without making a transaction.

For example, A wishes to pay B 0.5 BTC, but the smallest UTXO A has is UTXO_1, which contains 1 BTC. In this situation, A has to use the entire UTXO_1. When sending UTXO_1, she splits it into two new UTXOs of 0.5 BTC each, and she has to use both UTXOs in 2 separate transactions: she will send one to B as payment, and the other one back to herself. This will be illustrated more clearly in the next question.

3. How do transactions in Bitcoin work exactly?

Every transaction in Bitcoin has some inputs and some outputs. The inputs are UTXOs which belong to the sender of the transaction, whereas the outputs of a transaction are newly-generated UTXOs which are assigned to the recipient.

The locking and unlocking mechanism for Bitcoin transactions.

Bitcoin transactions ultimately rely on cycles of unlocking UTXOs, generating new UTXOs, and locking these UTXOs and sending them.

Step 1: Owner unlocks UTXO with their own private keys

Step 2: Generate new UTXOs of desired value for use in transactions

Step 3: Lock these new UTXOs and send them to the desired recipient.

Details

Each UTXO is locked with a locking script, ScriptPubKey. This script ensures that only the intended recipient of the transaction can access the bitcoin (UTXOs) being sent to them. ScriptPubKey consists of <PubKeyHash>, a hash of the public key of the recipient, which is related to the Bitcoin address of the recipient, as explained in Part 1 of our guide.

A recipient of a transaction can access their UTXOs by using the unlocking script, ScriptSig. ScriptSig is used by the recipient of the UTXOs to prove that they own the bitcoin stored in the UTXO. ScriptSig consists of <Sig>, a user’s Bitcoin signature generated using ECDSA, and <PubKey>, a user’s public key. Refer to the visual below for detailed look at how the UTXOs are unlocked.

A diagram to show the steps used to unlock a UTXO before it can be used

Firstly, <PubKey> is hashed and compared with <PubKeyHash> in ScriptPubKey. If they match, it means that the user trying to access the UTXO does indeed possess the public key associated with the Bitcoin address, and is thus the rightful owner of the UTXO.

Next, <Sig> is compared with <PubKey> to verify that the private key used to generate the Bitcoin signature is indeed the same private key from which the (already correctly verified) public key was generated. This acts as a second stage of security check on top of the public key check.

Only by using ScriptSig can the UTXOs be unlocked and used as inputs for a transaction. When generating the outputs of the transaction, the sender again locks the UTXOs with the ScriptPubKey of the recipient. Therefore, Bitcoin transactions are a continuous loop of locking and unlocking UTXOs.

4. Can I have an example of a Bitcoin transaction?

We can utilize an example to understand how Bitcoin transactions work. A cake buyer wishes to purchase a cake worth 5 BTC from a cake seller.

If the cake buyer has a UTXO worth exactly 5 BTC, she can use that in a transaction to purchase the cake from the cake seller.

However, if the cake buyer does not have a UTXO which is exactly 5 BTC, she has to choose a combination of UTXOs which cover the 5 BTC price (which could include choosing a UTXO with value more than 5 BTC, or a few UTXOs which sum up to more than 5 BTC).

In this case, she starts off with a balance of 4 UTXOs worth 3, 1, 1.5, and 4.5 BTC respectively, for a total balance of 10 BTC. Since she does not have a UTXO worth exactly 5 BTC, she picks a combination of UTXO_3, worth 1 BTC, and UTXO_5, worth 4.5 BTC, for a total input value of 5.5 BTC.

Since she wants to send 5 BTC to the cake seller, with her two inputs, she generates two outputs. The first one is a UTXO of 5 BTC to be sent to the cake seller, and the second one is a UTXO of 0.5 BTC to be sent back to herself.

A visual to illustrate how UTXOs are created and spent in a transaction.

On a transaction level, the cake buyer unlocks the ScriptPubKey of UTXO_3 and UTXO_5 with her ScriptSig, and uses these UTXOs as inputs for the transaction. Once she does so, she generates the two outputs and locks them with the recipient’s ScriptPubKey. When the cake seller wants to use this UTXO, he will have to use his ScriptSig to unlock it.

The Cake Buyer unlocks her previous UTXOs for spending, and creates new UTXOs to be sent to the Cake Seller and herself.

5. How does one broadcast transactions to other nodes?

There is no need to do this for most users. You simply use a Bitcoin wallet client, enter the details for the transaction you wish to conduct, and click send. The client will broadcast the transaction for you.

Since Bitcoin is a peer-to-peer network, the client searches for peers (nodes) to send the transaction to. When it can’t find any peers, it falls back on a list of reliable back-up peers hard-coded into the client.

6. How many transactions can each Bitcoin block have?

The number of transactions each Bitcoin block may have is dependent on the type and size of the individual transactions contained in that specific block. The original block size limit is 1 megabyte. If each transaction is arbitrarily small, then a Bitcoin block can have an arbitrarily large number of transactions.

In practice, the average number of transactions per block is ~2100, as of February 2019. This number is probably lower than it should be due to the presence of empty blocks being mined.

(Note: Segwit, a soft fork in the Bitcoin Network, allows transaction data to be stored in an extended block, allowing for blocks to be larger than 2 megabytes to store more transaction data. Segwit transactions comprise of approximately 40% of all Bitcoin transactions as of February 2019.)

Concluding Remarks

In this article, we looked into the details of the UTXO model and how transactions in Bitcoin work. In the next article, we will explain the final piece of the Bitcoin puzzle: mining. We will look at how mining works, and the role which mining plays in Bitcoin.

We see this guide as a continuous work-in-progress! Please leave any questions or remarks in the comments section and we will try our best to include them in updated versions of our guide. And if you found our guide useful, please leave some claps!

For more information on Everest, please visit our website.

--

--