Transaction Costs Overview

The following content is an excerpt from EWF's blog here:

Three key variables influence transaction cost
A transaction is any ‘write’ operation that changes the state of the blockchain (i.e., adds data or modifies values). Transferring tokens between accounts, deploying new smart contracts or accounts, and modifying the state of existing smart contracts are all examples of transactions. Most importantly, all transactions are not created equal: some are more computationally intensive than others, some are more urgent, some require greater degrees of privacy. As we’ll soon see, these differences from one transaction to the next can have an impact on ultimate transaction cost.

Three key variables influence transaction cost: 

1.Gas cost: A transaction’s computational complexity is measured in gas, a unit that assigns a numeric value to each operational code, or instruction, that will be executed to complete the transaction. This is basically a fixed, a la carte menu of required gas to run a given transaction. The gas cost of a transaction is thus determined by the amount and sophistication of code that needs to be executed as well as the amount and type of data that will be stored on the blockchain as a result. The more complex the transaction, the higher the gas cost.

2. Gas price: The total gas cost of a transaction is only part of the equation, however. Gas is an abstract value. To derive a concrete fee requires a gas price as well. Every user that initiates a transaction chooses a gas price they are willing to pay for that particular transaction, at that particular time. Users that want to have their transaction expedited, for example, might bid a higher gas price to ensure that it’s included as soon as possible in the next available block. Gas price is denominated in the native token or cryptocurrency (usually in miniscule units like gwei, which represent one billionth of an ether) of a public blockchain and is expressed in tokens per unit of gas.

3. Token value: Finally, token value—usually expressed in a fiat currency equivalent—translates virtual transaction cost into ‘real’ transaction cost. And when token value varies widely, perhaps due to token market volatility, resulting transaction costs can vary too.

Calculating a given transaction’s cost thus looks like the equation:

Tx Cost (unit: fiat $) = Gas Cost (unit: gas) x gas price (unit: token/gas) x token value ($/token)

Here’s how a fee would be calculated for a hypothetical transaction on Ethereum: 

50,000 gas x 10 gwei per gas = 500,000 gwei = 0.0005 ether

At an approximate value of $120 USD per ether, this would result in a transaction fee of $0.06. (Ether’s USD value over the past year has ranged from a low of ~$85 to a high of ~$800, resulting in a cost range of $0.04 to $0.40 for running the same transaction—assuming you otherwise hold gas price bids constant. In practice, users submitting a transaction to a blockchain typically calibrate their gas price bid relative to the token value at the time of the transaction.)

How to keep public blockchain transaction costs low

Those same three variables that define transaction cost also present opportunities to manage those costs and keep them low. For example:

1. Lean smart contracts can help keep gas costs down: App developers and other smart contract writers are incentivized to write lean, efficient code—writing smart contracts and initiating transactions that are as computationally efficient as possible.

2. Gas price bids should remain low on networks with high transaction capacity: Of the three variables that contribute to transaction costs, gas prices are arguably the most powerful lever, since the bidded prices are solely at the discretion of the user submitting a transaction to the network. For reasons we’ll explore below, in the absence of sustained block “congestion”, gas prices can remain low and stable.

3. “Just in time” gas price calculations mitigate some risks of token value volatility: For a variety of reasons, some token markets are more volatile than others. But just because a token’s value relative to a fiat currency changes, it doesn’t mean that transaction fees similarly change without warning. Users calibrate gas price bids at the time of the transaction, and thus will bid a denomination of tokens relative to the token’s value at the time. While it is possible that a past transaction fee could end up being significantly more or less expensive relative to current (or future) token value, transaction fees at the time they are incurred should remain relatively stable as a function of fiat currency. 

If users desire a low-cost network, why do transaction costs rise in the first place?

So why would anyone bid a high price for any transaction? Shouldn’t transaction fees remain very low, as rational users consistently attempt to minimize their costs? In reality, transaction fees vary precisely because of competition among users to get transactions confirmed. 

At any given moment there may be hundreds or thousands of transactions waiting to be confirmed and formally added to the blockchain. These pending transactions sit in a memory pool, or mempool, where they are ultimately selected by validators (miners in the case of proof-of-work blockchains) to be included in a block. But each block has a finite gas limit, meaning not all transactions can be confirmed at once. As a result, validators will typically give preference to the most-lucrative (or expensive, depending on perspective) transactions in the mempool. Transactions with lower fees may end up having to wait for their transaction to get confirmed.

Ultimately, fees are about transaction prioritization. The higher the gas price you pay, the faster your transaction will be confirmed. If you don’t care about the amount of time it takes to confirm your transaction, you can offer a very low (or no) gas price. However, with this strategy you run the risk that your transaction never gets confirmed, and just sits in the mempool queue indefinitely. 

Lessons from what we know about Ethereum

At the most basic level, transaction fees on Ethereum are determined as a function of supply (e.g., computational capacity of the network, as defined by block gas limit and block speed / time) and demand (i.e., number of pending transactions). Volatility comes into the equation because supply, namely block time and block gas limit, is essentially fixed, whereas demand fluctuates wildly due to number of users and the popularity of certain applications. Occasionally, transaction fee trends diverge from transaction volume, but generally the two are correlated. 

Looking at historical data, it’s fair to say that transaction fees are usually relatively modest (a few cents, or fractions of a cent) but occasionally highly volatile (up to $5 or more on a daily basis, up to thousands of dollars in isolated periods). Though the historical median transaction fee is roughly $0.05, for a developer looking to launch a mass-market application, knowing that transaction costs are “probably low, but potentially exorbitant” is unsatisfying at best. 

Going forward, increasing throughput capacity through various mechanisms promises to mitigate fee volatility and potentially lower fees more generally. But until scaling solutions are implemented, the risk remains.