Learning Modules

Transactions

Transactions on Ethereum (Currency, Gas Mechanisms, EIP-1559)

Ethereum's Currency

Gas fees are paid in Ethereum's native currency, ether (ETH). Gas prices are denoted in gwei, which itself is a denomination of ETH - each gwei is equal to 0.000000001 ETH ( ETH). For example, instead of saying that your gas costs 0.000000001 ether, you can say your gas costs 1 gwei. The word 'gwei' itself means 'giga-wei', and it is equal to 1,000,000,000 wei. Wei itself (named after Wei Dai, creator of b-money) is the smallest unit of ETH.

Why Gas Fees?

Gas fees help keep the Ethereum network secure. By requiring a fee for every computation, it prevents bad actors from spamming the network. Because transaction on the blochain is required to set a limit to how many computation steps of code execution it can use, this avoid accidental computational wastage such as the infamous infinity loop.

As an aside, the idea of introducing some computational puzzle ("pricing function") to reduce spam traces back to Cynthia Dwork and Moni Naor in 1992.

A relevant concept called hascash was introduced by Adam Back in 1997 as a Proof-of-Work system to control email spam. The idea is simple: users are required to compute a hash as a proof that a reasonable amount of computational resources have been consumed before sending the email.

A legitimate user is not inhibited by this process since the number of emails sent is presumably low, but a spammer with tens of thousands of emails will find it infeasible and expensive. While hashcash takes a considerable amount of computing resources to compute, it is easy and quick to verify.

In 1998, Wei Dai introduces b-money and proposed the idea of creating money via computational puzzles such as hashcash in a peer-to-peer network. Nick Szabo's idea called BitGold in 2005 and Hal Finney's idea of cryptographic currency combine ideas from b-money and hascash puzzles.

Transaction fee

Processing transactions on Ethereum network requires computational power and gas is the fee paid to node operators for providing that computational power to include a transaction into the blockchain (thus altering the state of the blockchain).

The more computation a transaction uses, the more gas is required. A transaction that sends ETH to 1 address would be computationally cheaper than a transaction that calls some arbitrarily complicated smart contract functions involving multiple addresses.

Gas Limit in Practice

With transactions, you also set a total gas limit, which is the maximum amount of gas you are willing to consume on a transaction. A standard ETH transfer requires a gas limit of 21,000 units of gas while a complicated transaction involving smart contracts between multiple addresses require more computation work, hence a higher gas limit.

Note that any gas not used in a transaction is returned to the user. Since the deployment of the London Upgrade, the amount returned would be:

Max fee - (base fee + tip)

gasreturned Image source: Ethereum.org

Supposed we put a gas limit of 50,000 for a simple ETH transfer, and the EVM consume 21,000, the remainder of 29,000 would be returned.

However, if we specify too little gas (say, 20,000) for the same transaction, the EVM will consume the 20,000 gas units in its attempt to fulfill the transaction, but unsuccessfully. The EVM then reverts any changes, but since the miner has already done the 20,000 gas units worth of work, that gas is consumed.

Historical Overview

Historically (prior to The London Upgrade on August 5th, 2021), transaction fees on Ethereum are determined by the Gas price * Gas units (gas used by the transaction).

Supposed Alice wants to pay Bob 2 ETH, and that this transaction costs 21,000 units of gas, and the gas price is 200 gwei, the total fee would thus be:

= gas units * gas price per unit
= 21000 * 200
= 4,200,000 gwei (0.0042 ETH)

A sum of 2.0042 ETH would be deducted from Alice's account, and Bob would be credited 2 ETH. The remainder of 0.0042 is historically paid to the miners (validators).

Gas Price vs Gas Unit

As a recap:

  • Gas price on the Ethereum network is determined by the demand and supply forces
  • While the unit of gas required is dependent on the computational cost to execute a contract

In practice, since we have little control over the computational cost of a contract, as well as the supply of computation power to execute that contract, the gas fee we pay is largely dependent on how fast we want our transaction to be executed.

Paying more gas fee increases the incentives of miners (validators) to include the transaction into a block.

Experiment

The following Demo fetches an estimation of time (in seconds) for a transaction to be included on the Ethereum blockchain.

If 💡 Price Recommendations is checked (default), it also optionally fetches the current Safe, Proposed and Gas Prices:

You can obtain an API key for the following interactive example by registering for an account on Etherscan

Gas Oracle from Etherscan

Gas Price

EIP-1559 (August 5, 2021)

The implementation of EIP-1559 in the London Upgrade changes Ethereum's market mechanisms for transaction fees. It replaces the first-price auction and replaces it with a base fee model where the fee is changed dynamically based on network activity.

This base fee is an algorithmically determined price, calculated by comparing the size of the previous block (amount of gas used for all the transactions) with the target size (15 million gas). If the block size is greater than the target block size, the protocol will increase the base fee for the following block -- and decrease it if block size is less than the target price. The protocol hence achieves an equilibrium block size of 15 million on average through this process described as tâtonnement.

Base Fee and Tips

To be eligible for inclusion, the offered price per gas must at least equal the base fee. As mentioned above, this base fee is calculated independent of the current block but is instead determined by the blocks before it, making transaction fees more predictable. This reduces the guesswork on gas required for each transaction.

This base fee is "burned", removing it from circulation.

Users that want to prioritize their transaction can instead add a "tip" (the Max priority fee being the maximum amount you're willing to pay as tip) to pay the validators through setting a priority. This tip is taken as compensation to the miners for executing and propagation the transaction. The total transaction fee is as such:

Using the example above, with Alice still paying Bob 2 ETH, and gas limit remain the same 21,000 units, what's left is to incorporate the calculation of (1) Base Fee and (2) Tip.

Assuming the transaction happens on block number 6, and block number 5's base fee is 142.38 gwei (). Supposed block number 5 has a size of 30M, block 6's base price is hence (). Alice also included a tip of 15 gwei, giving her the following transaction cost:

That's 3,678,738 gwei, or 0.003678 ETH.

When the transaction is included, 2.003678 ETH is deducted from Alice's balance. 2 ETH is credited to Bob's balance. 0.00336374 ETH is burned and miners receive 0.000315 ETH of tip.

Additionally, Alice can set a max fee (maxFeePerGas) for the transaction. Any difference between the max fee and the actual fee (max fee - (base fee + priority fee)) is refunded to Alice so she can set a maximum amount and not worry about overpaying well above the base fee when the transaction is executed.

In summary, because blocks on the blockchain have a fixed size, only a set amount of transactions can be included in any one block. When network activity becomes busy, setting a high Max priority fee on your transactions pushes it to the front of the queue by incentivizing the validators to consider this transaction first.

Metamask has some simple guidelines to picking the right gas fee:

High: This is best for time sensitive transactions (like Swaps) as it increases the likelihood of a successful transaction. If a Swap takes too long to process it may fail and result in losing some of your gas fee.

Medium: A medium gas fee is good for sending, withdrawing or other non-time sensitive transactions. This setting will most often result in a successful transaction.

Low: A lower gas fee should only be used when processing time is less important. Lower fees make it hard predict when (or if) your transaction will be successful.

Source: Metamask

The material impact of this EIP is to have transaction fees be more predictable for the user. Wallets and decentralized apps would also reduce their reliance on external oracles since the base fee is managed by the protocol itself.

This doesn't mean that transaction fees are cheaper since the intent of this EIP is on predictable base fee, and not necessarily cheaper gas (this is instead the intent of Ethereum Layer 2 Rollups).

Ethereum's Gas Burning Mechanism

With EIP-1559,the ETH spent as base fee in each transaction is "burnt", i.e removed from the supply pool. This makes ETH more scarce and in theory puts deflationary pressure on the overall Ethereum supply. As of this writing (22nd November 2021), Ethereum has achieved a 66.67% reduction in ETH issuance since EIP-1559 is deployed. When net reduction is above 100%, it would mean Ethereum is burning more ETH than it is issuing.

Modeling exactly how deflationary EIP-1559 will be is an area of active research, but some estimates that the annual supply rate of ETH would be reduced by 1.4%. Today, similar proposals have been drafted for other blockchains, such as this proposal for the Binance Smart Chain which introduces a regular fee-burning mechanism,

The London Upgrade

A summary of the London Upgrade:

  • Implemented on August 5th, 2021, to make transaction fees more predictable for users by overhauling the gas fee mechanism

  • Replaces the fixed-size blocks with variable-size blocks, so users did not have to wait for high demand to reduce during periods of high network demand

  • Each block has a target size of 15 million gas but, the size of blocks will increase or decrease in accordance with network demand, up until the block limit of 30 million gas (2x the target block size)

  • Every block now has a base fee (the minimum price per unit of gas for inclusion in this block, determined by supply and demand for block space). The base fee will increase and decrease by 12.5% after blocks are more than 50% full. For example, if a block is 100% full the base fee increases by 12.5%; if it is 50% full the base fee will be the same; if it is 0% full the base fee would decrease by 12.5%. The exponential increase of 12.5% makes it economically non-viable for block size to remain high indefinitely

  • Prior to the London Upgrade, miners receive the total gas fee from any transaction included in a block. Now, a priority fee (tip) mechanism is introduced to incentivize miners to include a transaction in the block. Miners will still find it economically viable to mine empty blocks as they receive the same block reward

  • A sender can additionally specify a maximum limit they are willing to pay (maxFeePerGas), and sender is refunded the difference between the max fee and the sum of the base fee and tip. The sender will never pay more than the market price for gas on that block (baseFeePerGas)

Knowledge Check

0 Tasks

Practical Exercises

Quizzes

EIP-1559 in the London Upgrade is effective at lowering the transaction fee across the Ethereum blockchain.

A transaction can include a `maxFeePerGas`, but how does Ethereum treat any gas not used in a transaction?

Which of the following is not correct about the priority fee?