2. Bitcoin Transactions#

This tutorial is an introduction to the world of crypto, through Bitcoin. We begin with a brief preview of what you can do on the Bitcoin blockchain, assuming you’ve installed the Electrum wallet. This demonstration will evidence the importance of your wallet choice, and how not all wallets offer the same features. Next, we dive into the world of Bitcoin transactions, taking a closer look at what happens behind the scenes. We explore how to analyse Bitcoin transactions online, providing insights into their inner workings. Finally, we conclude the tutorial by learning how to transfer assets between the Bitcoin and Ethereum blockchains, preparing you for the next tutorial in the series.

Satoshi’s place#

Before explaining let’s do. If you installed the Electrum wallet in the previous tutorial, you will be able to follow along for this section, otherwise, don’t worry; we will be using the XDeFi wallet for the rest of the tutorial.

There’s a lot of things you can do with your Bitcoin other than simply transacting, although it is true that most of the infrastructure built on top of the Bitcoin Blockchain is financial in nature. However, one non-financial application is Satoshi’s Place. We’ll be exploring Satoshi’s Place during this tutorial.

Satoshi’s Place

Satoshi’s Place is a public canvas, where anyone, with a few fractions of a Bitcoin (Satoshi/sat) can draw whatever they wish. The name ‘Satoshi’s Place’ has a dual meaning; as we mentioned, Satoshi Nakamoto is the alias used by the creator of Bitcoin, but it is also the name given to the smallest possible unit of Bitcoin that one can use in transactions. The “Satoshi”, named in honour of the creator of Bitcoin represents one 100 millionth of a Bitcoin.

Now, go ahead and open up Satoshi’s place and draw something. We will then proceed with analysing the transaction used to pay for your drawing.

Each pixel coloured costs one satoshi. At the time of the creation of this tutorial, 1000 satoshi or one one hundred thousandth of a Bitcoin is about 30 cents. This was enough for me to draw the following picture of a pair of cherries:

Untitled

What happens when you send a transaction?#

Note that drawing on Satoshi’s place uses the lightning network which is built on top of Bitcoin, rather than the Bitcoin network itself.

Once you click to submit the drawing you will be presented with a payments screen. Click on the “copy payment request” button

Untitled

and proceed to paste it into your electrum wallet by clicking on the button highlighted in red on the following screenshot.

Untitled

Now that we have submitted our drawing request, let’s look at what a transactions contains. Note that you are asked for three things, the address of who you are paying (”pay to”), the description of what you are paying for (”Description”) and the Amount (”Amount”) in mBTC or milliBit (one thousandth of a Bitcoin). Yet this is not exactly what is sent to the Bitcoin network. What is actually sent is the address, the amount and then a digital signature signed with your private key, to prove that it was really you who made that transaction. Hence, the description is only for your own accounting.

What a transaction is supposed to look like, UTXOs#

If we turn back to theory, a bitcoin payment works quite a bit like a cash payment. It helps to think of your Bitcoin as cash held in your wallet (rather than a bank card for Ethereum). When you first transferred money from the crypto exchange into your wallet, the crypto exchange gave you a “digital cash bill” (e.g. a \(X\) [coordinate with tutorial #1 on the amount] denomination bitcoin bill) for the amount that you transferred. Now that you’ve spent the ‘digital cash bill’ on the artwork in Satoshi’s place, you’ve received some digital cash back equal to the value of your original bill minus the cost of the drawing. (This will become clearer as we analyze a transaction.) Here’s the significant difference compared to the world of fiat cash: while euros come in limited denominations like 500, 100, 50, 20, etc., in Bitcoin, you have a ‘bill’ for every value between 1 satoshi and 1 Bitcoin. To draw a parallel with our cash analogy, the term ‘UTXO’ in the Bitcoin world represents a ‘bill’ and is short for ‘Unspent Transaction Output.’

The crucial point to understand is that the money you hold in your wallet isn’t combined into a single UTXO or bill. Instead, each transaction generates a separate UTXO. Your wallet’s balance is simply the sum of all these UTXOs. Wallets help manage these UTXOs and keep your funds organized. Without a wallet, you’d have to manually track each UTXO.

In practical terms, this means that each UTXO can be spent independently in a single transaction. For example, if you have a UTXO worth 0.5 Bitcoin and another worth 0.2 Bitcoin in your wallet, you can send 0.25 Bitcoin to one person from the first UTXO and 0.2 Bitcoin from the second UTXO to another person in one transaction, which can help minimize transaction fees.

Moreover, the UTXO system has significant implications for privacy. While it’s challenging to trace who owns a specific UTXO (i.e., who controls the private keys), it’s relatively easy to trace the history of that UTXO, meaning the transactions that created it. This is because the Bitcoin blockchain records UTXOs.

In the example below, Alice starts with a total balance of 21 BTC before the transaction and ends with a balance of 15.99 BTC after. She chooses to pay using UTXOs of 2 BTC and 4 BTC. After paying a 0.01 BTC transaction fee, she receives a UTXO of 0.99 BTC as change, while Bob receives a UTXO of 5 BTC.

Untitled

Mempool#

Transacting with Bitcoin, or any other Blockchain based cryptocurrency for the matter, can be thought of as writing to a long ledger of transactions. However, transactions aren’t automatically added to the ledger. First you let the network, i.e. the miners, know that you want to transact by having your transaction sent to a waiting area, called the “mempool”, where all transactions that have yet to be settled wait (but no funds have actually moved and the decision can be reversed at this stage). Although it’s called “the mempool”, it’s better to think of it as “the mempools” since each miner has their own, where they keep track of the transactions that they know of. Miners have the ability to examine the mempool and select the most appealing transactions, often those that offer the highest fees. Each miner independently decides which transactions to include and competes with others to add these selected transactions to the blockchain, forming a ‘block’ within the ledger. The time it takes to incorporate such a ‘block’ of transactions into the blockchain is known as the ‘block time,’ which is approximately 10 minutes in the case of Bitcoin.

To put it simply, approximately every 10 minutes, the most desirable transactions from the mempool are added to the blockchain and thus considered executed. However, not all transactions in the mempool can be written into the blockchain simultaneously because there’s a maximum limit on the number of transactions that can be included in a single block.

Note that a transaction can live in the mempool forever, since it’s a list of potential transactions that isn’t coordinated. Every miner can have a different mempool (although they do share their mempools, it’s unlikely that two mempools will be exactly the same), there is a possibility that all miners somehow manage to forget that this transaction was submitted at the same time, but that does not often happen. On Bitcoin, cancelling a transaction that is in the mempool but has not been confirmed is “easy”; simply send a transaction with the same UTXO that pays a higher transaction fee - you don’t have to spend the same amount - the only thing that matters is that the UTXO (or bill) that you use to pay is the same. It then becomes more likely that the transaction paying the higher fee will be added to the blockchain first, as it’s more desirable for the miner. If someone tries adding the lower fee original transaction they will get an error since the UTXO will show as being already spent.

  • More details on execution and block size

    There is also the issue of “block finality” - miners can decide that the latest block (or any other block for that matter) is not valid, for instance, if the block contains a clear breach of some protocol, and submit other blocks in hopes of changing the transactions that were added to the ledger. Hence, although this is exceedingly rare, transactions are considered, by best practice, to be irreversible after only 6 blocks on Bitcoin (although finality is a probabilistic concept, and even at two blocks it’s quite rare to have your transaction be suddenly removed).

    There are three main reasons for having a finite block size (see here for a longer explanation):

    1. It helps with reaching an agreement on what is valid, by not allowing unreasonably large blocks and makes including empty transactions economically undesirable.

    2. It helps keep people from using the block size to reach a competitive advantage in how fast they can verify transactions.

    3. It makes running the software to mine blocks more accessible to those without really beefy computers.

Reading a bitcoin transaction on Blockchair#

While it’s valuable to grasp the technical aspects of a transaction from a computer science perspective, if you want to observe real Bitcoin transactions occurring on the blockchain, you’ll need to use a tool known as a ‘blockchain explorer.’ Blockchair is a popular example of such a blockchain explorer. Below, you can see a screenshot of Blockchair’s homepage.

Explorateur Bitcoin

Untitled.png

The landing page shows general information about the Bitcoin blockchain rather than any specific transaction. The terms present on the screenshot are broken down below

  • Dominance: Market cap of Bitcoin as a percentage of the total market cap of the 125 most valuable cryptocurrencies.

  • Size of the blockchain: Total size of the ledger containing every single transaction in the history of Bitcoin

  • Transactions: Total number of transactions in the history of blockchain, this might seem low, but consider that currently there are about 500k Bitcoin transactions every day. Admittedly this is a far cry from the over half a Billion daily transactions handled by Visa and the 200 million transactions by Mastercard (Source: https://www.statista.com/statistics/261327/number-of-per-card-credit-card-transactions-worldwide-by-brand-as-of-2011/, alternative: https://www.visualcapitalist.com/visa-mastercard-unionpay-transaction-volumes/)

  • Outputs: Remember how Bitcoin is like cash? Directly this is the total number of recipients (including yourself in receiving change) from all transactions combined, or it can be thought of as the number of bills in circulation

  • Addresses: Total number of Unique Bitcoin addresses ever created

  • Network nodes: Total number of miners

Gas#

What I haven’t mentioned yet pertains to ‘frais’, or what is more commonly known as ‘gas.’ Understanding gas requires some insight into the architecture of the Bitcoin blockchain. To begin, miners have two ways of earning income: one is through the reward they receive when they mine a block, and the other is by collecting fees from users who want their transactions recorded. The practice of distributing Bitcoin rewards upon mining each block inherently leads to inflation. As the total supply of Bitcoin is fixed, this income source becomes more uncertain over time. Consequently, miners and the network must increasingly rely on transaction fees. Since the number of transactions in a block is limited (we’ll delve into this in future tutorials), there’s competition among transactions to be included in any given block based on transaction fees. Transactions with higher fees are more likely to be included, while those with minimal fees may linger in the mempool for extended periods, even years. This creates an open market where transaction fees rise with increased network activity and decrease as activity subsides. The ‘Fees’ counter displayed under the mempool section in the screenshot above represents the total amount of transaction fees currently in the mempool. Not all of this will be utilized when a block is mined, as some transactions may be left out.

The precise amount of gas you must pay depends on the complexity of your transaction. More complex transactions incur higher costs, while simpler ones cost less. It’s important to note that complexity isn’t synonymous with transaction size; for instance, a one-satoshi transaction will cost nearly the same as a transaction transferring 100 Bitcoin. In this context, complexity is measured in terms of computational resources used. Since multiplying a value by 100 is roughly as complex as multiplying it by one one-hundred-millionth, the transaction fee remains nearly identical, with the only difference being that the latter may require slightly more storage space, typically only a few hundred bytes more. In contrast, a transaction utilizing smart contracts (which will be explained in a later tutorial) will consume more computational power and consequently be noticeably more expensive.

Bitcoin uses a unit called a vByte (virtual Byte) to measure the data consumed by a transaction. When conducting transactions, it’s crucial to verify whether transaction fees are expressed as cost per vByte or as the total cost per transaction.

It’s important to note that Bitcoin transaction fees can vary significantly throughout a week. For instance, the chart below illustrates Bitcoin gas fees in satoshis from 13/08/2023 to 20/08/2023, ranging from a low of about 21.09 satoshis per vByte to the current rate of 22.7 satoshis per vByte.

Untitled

Converting Bitcoin to Ethereum#

Since the next tutorials will all deal with Ethereum, we will now work through how to convert Bitcoin into Ether. If you refer back to the first tutorial you will be reminded that the two blockchains are completely separate entities. This means that converting from one crypto to the other is not straightforward. Usually, this is done through a centralised exchange like the one that you originally purchased Bitcoin from. Yet the cryptocurrency world is trying to move away from it since it requires going through a third party, and serves as a bottleneck to the decentralised ideal. Hence, let’s use a decentralised alternative.

We will be using an application called THORSwap (get used to the weird names, there’s a lot of them still to come):

THORSwap

Although we will cover this topic more in depth in a future tutorial, THORSwap is a kind of cross-chain decentralised exchange (DEX) combined with a “bridge”. A bridge is, as the name suggests, supposed to serve as a way to bridge between two Blockchains. Usually they achieve this by having people deposit tokens into their protocol to serve as reserves, which other people can then use to swap between currencies.

To use THORSwap we must first connect our wallet to it. Behind the scenes, when you connect your wallet to a decentralised application, or dApp for short, it shares your public address with it, so the app can then look your address up and establish what funds you have on it. This is different from giving it permission to access your coins. We can connect to THORSwap by selecting the Connect button on the top right.

Untitled

Select Bitcoin and XDEFI:

Untitled

This will open up a popup from your XDEFI wallet where you need to authorise the connection, remember this only shares your address with the webpage so that they can see how much crypto you have in your wallet.

Untitled

Once you have approved connecting your wallet you will see the following page on THORSwap:

tempsnip.png

Since we want to convert Bitcoin to Ethereum, click on the blue button in the middle with the red rectangle drawn around it. This will switch around the order of the currencies, and display a field below titled “Recipient Address”. We now want to go to our Ethereum MetaMask wallet and copy and paste the address from it into the “Recipient Address” field, like we did in the previous tutorial when we were withdrawing money from the centralised exchange. Once you’ve entered your Ethereum address (make sure to double check it since again transactions are non-reversible) and chosen the amount that you want to transfer, you will be shown the following page.

Untitled

As you can see I am paying 4.042$ for the swap in gas fees, which is fairly steep considering that I am only transferring slightly under 50$ worth of BTC, but remember that this fee stays the same regardless. If I am transferring 5000$ worth of BTC or 50.000$ worth of BTC, it would be the same. Note that if you click on the little arrow next to the fees and then on “Details” under “Network fee” you will see that THORSwap doesn’t quote the “Inbound Network” fees but only the “Outbound Network” fees.

Let’s use an analogy with traditional finance to explain this - what we’re trying to do is send euros to HSBC from our BNP Paribas account, have HSBC convert those euros to dollars and then send those dollars to our dollar account at Bank of America. THORSwap is only quoting the transaction fee for HSBC sending dollars to Bank of America and completely ignoring the price of sending euros to HSBC. We will see that once we go to confirm the transaction, that the price has gone up.

Once you’ve confirmed your address and the amount, press swap. This will first take you to the following page to confirm the transaction form the perspective of THORSwap

Untitled

We’ll discuss the concept of ‘Slippage’ in a future tutorial. You may also notice that the fee has changed. This happens because the BTC and USD market prices can fluctuate between the time I initiated the transaction and the moment I noted down the steps for this tutorial. What’s even more surprising is that there’s no guarantee that the fee quoted in BTC hasn’t changed either. In the world of cryptocurrencies, everything is in constant flux, and prices often shift between the initial setup of a transaction and the final confirmation. Therefore, it’s crucial to ensure that the amounts align with your preferences at each step. We’ll cover how dApps determine their market prices in a future tutorial.

Now that we’ve confirmed our intentions with THORSwap, another pop-up will appear from our XDEFI wallet, prompting us to confirm the transaction. Here, you’ll see the cost of executing the transaction on the Bitcoin blockchain, or, as per our earlier analogy, the fees for sending euros from BNP Paribas to HSBC. The three options—Average, Fast, and Fastest—indicate the level of fees you’re willing to pay. You can also manually set the fee, but we’ll leave that for when you’re more experienced with cryptocurrencies. A higher fee increases the likelihood of your transaction being picked up from the mempool and processed. If the fee is set too low, the transaction can remain in the mempool indefinitely. From personal experience, unless you’re in a rush, even a low or ‘Average’ fee is usually sufficient to complete the transaction within a few hours, or at most, a day. Go ahead and confirm the transaction.

Untitled

If you’re lucky, the transaction will have gone through. If you’re not, then you will get an error saying that there are “insufficient funds in wallet”. This happens when you’re trying to send everything you have in your wallet at once, and the gas prices change enough during the time it took you to set up the transaction and finally confirm it, that you now no longer have the required amount of funds on your account to cover the amount that you want to swap and the gas fees at the same time. The easiest way to get around this is to go back to the beginning and try again, but this time do it faster. The slightly more advanced way is to set the amount of gas you’re willing to pay yourself and hope that that this is enough to get your transaction through. If you keep failing, try sending a bit less than all your assets over.

Individual transactions#

Now let’s look at what actually happened when we sent assets to THORSwap, and learn how to analyse a single transaction on Bitcoin. Open up XDEFI again and navigate to the Activity tab, then select Bitcoin:

Untitled

Click on the latest transaction and you will automatically be redirected to the Blockchair, showcasing your transaction.

Untitled

The sender in this transaction is your own address. In the screenshot, there are two recipients shown. It’s essential to remember that in Bitcoin, ‘recipients’ include anyone who received some cash from the transaction, which can even include you if you received any change. In the example transaction, no change was returned, so there are only two recipients. The bottom recipient has a clarifying comment ‘OP_RETURN’ associated with it, indicating that it’s a recipient used to record a message on the blockchain. This message might be something like ‘Transaction successful at the current datetime.’ By process of elimination, the other recipient must be the THORSwap address.

If you wish to track the fate of your UTXO, you can click on the recipient’s address to view their transactions. Alternatively, you can click on the small arrow below and to the right of the recipient’s address, if the coins have been spent. This action will take you to the next transaction involving that UTXO. In this view, you’ll find the same information as before, with multiple sender addresses and recipients. In the screenshot, you can observe that the first sender address and the second recipient address are the same, indicating that this must be the change address, corresponding to Alice’s wallet in the initial diagram. To follow the money and understand its use, you can simply click on the right-pointing arrow once more and continue your analysis.

Untitled

Next tutorial#

In the next tutorial, we will cover similar concepts to what we’ve just discussed, but this time, we’ll be exploring the Ethereum blockchain. This underscores the fact that each blockchain is unique, and while transitioning from one to another is becoming more seamless, it’s still essential to be aware of their differences.