So, in this article we will be deconstructing the transaction flow and fees calculation. While we will use bitcoin transactions as live example, most of these concepts are true for other cryptocurrencies too.
Flow chart of a cryptocurrency transaction:
Let’s look at each of these steps closely.
Ledger, as we saw in our last article, stores amount and ownership information. If there is a change in ownership, entries added to the ledger. Finance companies use something called double bookkeeping. It utilizes two accounts to track this change. Both these accounts should always tally.
Example – I deposit $100 in my account, the bank creates two entries
|My Account||Bank’s Account|
Positive number denotes an asset while negative denotes a liability. I own the money so it’s an asset for me. While the bank needs to pay whenever I demand so, it’s a liability for them.
On withdrawing $10, both my asset and bank’s liability decrease:
|My Account||Bank’s Account|
As you will note, total for both sides is 90.
This is a simple example of a ledger flow. Cryptocurrencies have their own unique way to create these entries.
Transaction Input and Output
Public ledgers like a blockchain have a fixed amount of coins. So, tracking all coins – new and old is necessary. Cryptocurrencies use a system known as Transaction inputs and outputs.
Let’s look at how a cryptocurrency ledger works. Alice mines 100 coins:
Now, she sends 50 coins to Bob (assuming fees are zero). Alice’s existing coins will act as input and create two outputs – Alice gets 50 in change and Bob gets 50 in credit:
Total of coins held by Bob and Alice is 100 ie the coin mined by Alice.
Next, Bob sends 25 coins to John and Alice mines another 100 coins. Freshly mined coins don’t have any previous input. While there are another two outputs created for Bob-John transaction:
Now that we have 100 new coins, total in white boxes is 200.
Let’s say Alice sends Adam 40 coins. Wallets will always try and optimize transactions. So, it will combine two inputs to create the two outputs – Alice’s change and Adam’s credit:
The total still doesn’t change and it remains 200.
Now, these are just some of the possible input/output combinations. It is possible to have 100s of inputs going to one output or 1 input to 1000s of output.
So, in a cryptocurrency we can trace all coins back to their mining source. All transactions are connected in a chain. Hence, the name blockchain? 😉
These coins are new so, we don’t have any inputs.
We follow these mined coins (~16 BTC):
(You can check the transaction here. Click + sign from the green highlight box to get this view).
Left side are inputs and right hand are outputs. Here, 7 inputs from same account are connecting to multiple outputs. One major difference you will notice is that our account doesn’t appear on right hand side. This is happening because there is no “change” left for our account – all 130 BTC has been debited.
We can further check the first 10 BTC (output) transaction.
(Note: Check this link to see full transaction)
Here, we see another possibility – multiple inputs from many accounts connected to multiple smaller outputs across different accounts.
So, when you press the “Send” button on a cryptocurrency wallet, it creates an output to send coins to recipient(s):
- If you spend some but not all coins, there will be two outputs – one to give you back some change and second pays the recipient.
- If you send all the coins in your account then there will be only output.
Unspent Transaction outputs or UTXO
In my piece on Bitcoin Energy, I said “95% transactions take 22 second (to spread through bitcoin network)”. Someone asked me – “You still didn’t explain how exactly does bitcoin solve double spending? Without a fail safe I can spend any coin twice within those 22 seconds or even before the first confirmation.”
The answer is – “unspent transaction outputs” or UTXO. Any coin which is not an input to another transaction is a UTXO.
If you look at my cryptocurrency ledger example above, white boxes are the UTXOs.
Live example from bitcoin:
We see 0.56 BTC broken down to 0.55 BTC (spent) and 0.004875 BTC (unspent).
Why is 0.55 BTC showing as spent? Because of this transaction:
In this case, both outputs are still unspent.
Wallets can only use UTXOs to create proper input/output pair.
Once we have outputs in place, transaction is send to a memory pool or mempool. Transaction remains in the mempool until a miner includes it in a block. You can find all pending transactions in a cryptocurrency by looking at the mempool.
Bitcoin Mempool charts are here:
This data shows aggregate size of all transactions in current bitcoin mempool. You can find also find all pending transactions:
Too many transactions in a mempool means slower transactions. This tends to happen during weekends and holidays. So, it is always better to check the mempool before submitting a transaction.
People also use large mempool as a proxy for an overwhelmed or active currency. You might see headlines saying “x number of pending transactions”. These types of analysis can sometimes be faulty.
For example, the smallest bitcoin coin size is a satoshi or 0.00000001 BTC. But, you cannot spend less than 5300 satoshis or 0.00005430 BTC in a transaction. So, I can create 10k transactions with zero fees and send it to the mempool. This is like spamming someone’s inbox with millions of emails. It will cost me 0.5 BTC or $5000 at current bitcoin price. In turn the mempool will be bloated with 10k pending transactions.
A traditional accounting system adds ledger entries into the book, as soon as transaction arrives. In my previous post, we saw how things are difficult for a cryptocurrency.
Everyone needs to be on the same page for the cryptocurrency to work. But there is always a delay/latency in sharing information. So, cryptocurrencies collect a bunch of ledger entries and add it to the blockchain at once. Furthermore, as there should be minimum delay/latency in sharing updated information. So, cryptocurrencies also limit how many transactions can be collected. This limited collection is enforced through the block size mechanism. Hence, the size of input/output combination becomes very important.
Let’s take bitcoin as an example. Bitcoin block size is 1 MB. One input is nearly 150 bytes and output is 40 bytes.
So, if we look at the Alice to Bob transaction above i.e. one input and two outputs, transaction size will be 230 bytes (150 + 40 * 2). One bitcoin block can contain 4350 such transactions.
But, if we look at the Alice to Adam transaction where there are two inputs and outputs, transaction size will be 380 bytes. One bitcoin block can contain only 2630 such transactions. This is 60% reduction in transaction storage.
Cryptocurrencies offer a myriad range of transaction types. In Bitcoin, we have:
- Normal Transaction – These are transactions we have been discussing a lot. Alice to Bob transaction is a normal transaction.
- Multi-sig transactions – We have discussed multiple signatures or multi-sig in our first post. These are transactions where payment goes to an address with multiple private keys.
- Metadata transactions – In this transaction type, there is no coin exchange. Instead people use bitcoin blockchain to store some information. Something like Nelson Mandela pics or OMNI transactions
- Unknown transactions – These are transactions which don’t fall in any of the three categories.
If we look at bitcoin average transaction size, it varies a lot:
Since early December, average transaction size has been between 369 to 689 bytes. At the lower end, bitcoin block can contain 2710 transactions. While on the higher end this figure reduces by 50% down to 1450 transactions. This is a huge variation in transaction performance.
Miners play a big role in transaction performance due to two major aspects:
- Location – Miners need to see your transaction before they can add it to the blockchain. Most of cryptocurrency miners are based out of China. So, if you located in place having huge latency to China, your transactions will be delayed.
- Block sizes have an important caveat – it is the maximum possible size of a block. Blocks which are smaller in size are also valid. Even the blocks with zero transactions.
So, in bitcoin there are valid blocks which are less than 1 MB. Data on historical bitcoin block size can be found here:
In last one year block size has varied between 0.58MB to 1.08MB.
Miners also have an upper hand compared to other parties in any cryptocurrency. They can select and prioritize transactions irrespective of fees. So, they not only pay lower fees but also have fastest transactions.
If you look at one of the previous example bitcoin transaction:
Size of the transaction is 33547 bytes. Ideal fees for this transaction is 0.14 BTC or $1700. But, the actual fees paid was 0.0003388 BTC or $4.
Additionally, lot of mining pools provide paid transaction “acceleration” services. They will take your transaction and try to included it in the next block.
At this point the concept of fees should be self-explanatory. Users bid on limited block space via fees. You pay more fees for a faster transaction. As the measurement for block space is MB, fees are calculated as “coins per byte”. So, fees are independent of coin amount. For example, it is possible to send 0.01 BTC and 100 BTC using same fees.
Just like any market function, fees are dependent on supply and demand. In this case, supply is the availability of blocks.
- If block size is too low, fees will be high.
- If block generation is slow, fees will be high.
Similarly, demand is on the transaction side.
- If you have too many inputs/outputs you transaction size and fees will be more. So, always optimize for transaction size. For example, if you look at the Alice-Adam the fee is about $21. It is possible to complete the transaction in $12, if we use 50 coin output to 40 for Adam and 10 for Alice. But what happens if Alice now need to send 12 coins? She needs to pay $21 because it will require two outputs. Combining is required at one point or other. Doing it as early as possible is the key lowering future fees. So, find a good wallet which can do that for you.
- If there are too many transactions fighting for the same spot, fees will be high. Mempools will shows you if there is too much competition.
- If someone pays higher fees for their transactions, rest will need to follow their lead.
Finding lowest fees
Most wallets have an inbuilt mechanism to calculate lowest fees. You can also use other websites to find lowest fees. An example site for bitcoin is:
This page lists transactions with worst fees on top.
It shows 4 transactions with zero fees per byte. These transactions will complete in anywhere between 780 minutes (10+hrs) to never.
As you scroll down, fees will increase and transaction get faster. Last line transactions have the highest fees and fastest transaction time.
Here, we see 16500 transactions with 581+ satoshis or 0.00000581+ BTC per byte. These transactions will complete in next 30 minutes.
Sweet spot for fees is towards end of the green zone.
As per this screenshot, best fees is anywhere between 0.00000450-460 BTC per byte. A transaction with 2 inputs and outputs is 380 bytes. So, if you think about Alice sending bitcoins to Adam she will need to pay 0.00170-0.00175 BTC in fees. At current exchange rate it is nearly $21.
You will find people claiming that their cryptocurrency has the lowest fees. I hope you can use information discussed in this article to evaluate and arrive at an informed conclusion.
The way forward…
This discussion will not be complete without answering questions like – What is the future of fees in cryptocurrencies? Is bitcoin scalable?
There has been lot of work done on the demand side. Transactions can now be a bit smaller due to Segregated Witness or Segwit which was first discussed in 2015. Litecoin activated Segwit in May 2017 and Bitcoin August 2017. Segwit also changed the block size parameter and introduced a new term called block weight. Due to this change, bitcoin blocks can now be nearly 4 MB in size.
There is also work being done on a new scaling solution called Lightning Network which was proposed in early 2017.
In comparison, trying to change the supply side of equation by increasing block size has been controversial. We have discussed earlier that it takes 13 seconds to propagate 1MB blocks. People opposing size increase fear that bigger blocks will cause further delays. So, they might end up mining only orphan blocks and never receive any mining rewards. So, all rewards will go to handful of miners with faster connection and lesser latency. They call it as centralization of mining power.
But, the block size controversy has gotten progressively worse and led to creation of an entirely new coin called “Bitcoin Cash” or BCH.
Interesting fact – In the BTC vs BCH debate both side accuse other of not following Satoshi Nakamoto’s dream. It is not often highlighted that the first version of bitcoin had 32MB block size. He later reduced it to 1MB. There is no official explanation from Nakamoto on size reduction or why 1MB was an ideal choice.
Still there is a huge amount of pending research on block size. For example, in October 2017, researchers from Bitcoin Unlimited presented a paper showing off 1GB block size.
In conclusion, bitcoin and other cryptocurrencies are cutting edge research combining two different fields – money and cryptographic technology. This might be the worse combination in history but with so much of research still pending, writing off cryptocurrencies might be too early.
Appendix – Triple Entry Accounting
This part is specifically for people interested in accounting so skip it if you don’t want to go there.
People often say triple Entry Accounting is one of the major benefits of using a blockchain. But there is a lot of confusion on what exactly is triple-entry.
Some people incorrectly think it is about the public nature of blockchain. They think if we add all transactions into a public book that is our third entry.
There is also some confusion over the origins of this method. People often incorrectly attribute it to Momentum Accounting for Trends: Relevance, Explanatory and Predictive Power of the Framework of Triple-Entry Bookkeeping and Momentum Accounting of Yuji Ijiri. This is because usage of a “third entry” was first proposed in this book. But, the proposed system by Ijiri is a complex beast. The proposal is to tie accounting to forecast. So, every credit/debit will cause the whole budget/forecast change. As, blockchain don’t exactly have an in-built forecast Ijiri’s concepts are not applicable.
The proposal for a blockchain type accounting comes from a separate work by Ian Griggs. He proposed that each credit/debit entry should have a third entry – unique cryptographic signature. Systems will not accept transactions with invalid cryptographic signature.
Now if you go back to the Alice-Bob transaction it is not exactly a two-entry system. We don’t have a book or entry storing Alice’s debit and Bob’s credit separately. The whole transaction is more like a single-entry system operating at the blockchain level. Blockchain had 1000 coins, when Alice completes mining the first block, she gets 100 coins. When she pays Bob, blockchain debits her account and credits Bob 50 coins, so on and so forth. This total will never exceed beyond 1000.
But blockchains implement a form Grigg’s proposal – all entries have an unique cryptographic signature in form of the mining hash. If the hash is invalid, entries cannot be created because there is no block.
Also published on Medium.