In the last post we also learned that each block consists of metadata and some number of transactions. We left some questions unanswered, though. For example:
- How do transactions get included in a block?
- Are they processed in the order they’re submitted?
- If not, what determines priority?
Sending a transaction on a public blockchain, like Ethereum, requires a small fee. Unlike most fees in life, you get to choose how much you want to pay — even $0.00. Here’s the catch: supply and demand determines whether or not your transaction gets included in a block and executed.
An example should help. Let’s say you want to send $20 to a friend. Along with your $20, you decide to include $0.01 as a transaction fee. When you confirm this transaction it is not instantly executed, but instead becomes a pending transaction and is added to the transaction pool — the group of all transactions that have been submitted, but not yet added to a block.
In general, the higher the supplied fees, the faster the transaction makes it into a block. If there are thousands of transactions in the transaction pool willing to pay at least a $0.05 transaction fee, you can expect your transaction with a $0.01 fee to wait in the pool until the others have been processed.
When it comes to the day-to-day use of Ethereum, most wallet apps will evaluate the current network conditions and provide at least a couple of options for your transaction fee. These options are often presented in terms of how quickly you need the transaction to be processed. For cases where there is no urgency, you can select a cheaper fee and wait. If it’s important that the transaction be executed as quickly as possible, you can pay a little extra.
At the time of writing, there are over 30,000 pending transactions in the transaction pool. Many of those will likely never be executed, because their transaction fees are insufficient. Want to explore the data yourself? Etherscan displays pending transactions here.
You may recall this teaser from the last post:
In general, the more complex the transactions are, the fewer you can fit within one block. We’ll explore those more complex transactions in a future post in this series.
Our examples so far have included straightforward transfers of value from one party to another, but transactions can be arbitrarily complex. As an example, one transaction may send money to three different destinations. This complexity has implications on transaction fees.
Every transaction on the Ethereum blockchain changes the state of the world in some way, e.g., the recipient of a transaction now has more money and the sender has less. Each of these changes requires some amount of computation (i.e., work by a computer) to be executed. We use the word gas to describe this concept. A simple transfer of value requires 21,000 gas, for example.
The amount of gas required to complete a transaction is calculated by your Ethereum client and is nonnegotiable. So what happened to being able to pay whatever you want for a transaction fee? That’s still true; the part you do have control over is the gas price you’re willing to pay.
21,000 gas * $0/gas = $0.00 fee
21,000 gas * $0.00000095/gas = $0.02 fee
Gas and gas price are important metrics in Ethereum, but they are clearly not very human-friendly numbers. Fortunately, as noted earlier, users of Ethereum don’t have to understand these concepts before using the technology. Modern Ethereum wallets can be expected to hide the complexity and present users with some simple options, e.g., $0.02 or $0.04.
Finally, we can put all the pieces together with one more detail: each block has a maximum gas limit. At the time of writing, that limit is around 10 million gas per block. With some simple math, we can find the maximum possible number of transactions in one block:
10,000,000 gas limit / 21,000 gas per transaction ≈ 476 transactions
This threshold is never met in reality, partly because Ethereum is regularly used for transactions that require more than 21,000 gas. In fact, the only limit to how much gas one transaction can require is the block limit itself. That is to say, one block could be filled by one very large transaction. You wont find many such transactions though, as they are expensive and impractical.
Whew! We covered a lot of ground there. Let’s make sure it all sunk in.
Quiz yourself — Here are the next set of questions you should be able to provide an answer to (however brief):
- What happens when you submit a transaction?
- How are transaction fees determined?
- Why might a transaction not get processed?
- How is the number of transactions per block restricted?