Part 3: Decoding Ethereum dApp Development: EIP-1559 explained in detail

Simplifying key concepts in EVM blockchain development: Nonce, Gas, Gas Limit, Gas Price, maxFeePerGas, maxPriorityFeePerGas.

ยท

3 min read

Play this article

I have already described what nonce is, what problems you might encounter with it, and the generic transaction fee structure. What is not yet covered and important is the new transaction type introduced to the Ethereum ecosystem with EIP-1559 improvement.

EIP-1559 explained

EIP-1559 is an upgrade to the Ethereum network that changes how transaction fees are calculated and processed by the network. It was enabled during the London hard fork on August 5th, 2021. Instead of using gasPrice as a mechanism of bidding the higher price for your transaction to the miners - validators these days - it consists of the block-based fee, which must be paid every time, and the transaction sender max fee, which the sender is willing to pay as a premium on top of the base fee.

๐Ÿ’ก
You can think about this approach as a two-step process. In the first step, every network user who wants to send a transaction must pay a base fee for "regular" processing time - base fee. If the user wants to speed up the transaction and include it in the blockchain faster, it's possible to tip a priority fee on top of the base fee. The bigger the tip, the higher the probability of being included in the block faster.

baseFeePerGas

baseFeePerGas tells you what is the next block base fee everyone must pay. This fee is burnt by the Ethereum blockchain and not distributed to the validators. To get the base fee, you can use the following code snippet.

// yarn add @tatumio/tatum

import { TatumSDK, Ethereum, Network } from '@tatumio/tatum'

const tatum = await TatumSDK.init<Ethereum>({network: Network.ETHEREUM})

const block = await tatum.rpc.getBlockByNumber('pending')

console.log("base fee in wei", parseInt(block.result.baseFeePerGas, 16));

tatum.destroy() // Destroy Tatum SDK - needed for stopping background jobs

maxPriorityFeePerGas

maxPriorityFeePerGas is the tip you want to provide to the validator for prioritizing your transaction. It is paid on top of the base fee. The bare minimum to enter is 1 wei, so you are incentivizing the validator at least slightly to include your transaction in the block.

maxFeePerGas

maxFeePerGas is the total final amount of fee you want to pay for a gas unit, something similar to gasPrice in the pre-EIP-1559 setup. The calculation is super simple - maxFeePerGas = baseFeePerGas + maxPriorityFeePerGas.

When to use which value

You can provide both, one of them, or none of the values during the creation of your transaction.

If you want to be sure that your transaction will be included in the block, providing maxPriorityFeePerGas is the option for you. With this filled, you are the owner of the tip you are offering to the network, and baseFeePerGas will be calculated for you.

When you provide maxFeePerGas, you are giving away the control of the tip and the base fee, but you know that you will not pay more than the specified amount. This could be helpful in the situations of recent spikes in the price on the network.

Providing both values at the same time gives you the best flexibility. You define the maximum fee you will pay and the tip on top of the base fee.

Summary

It's not easy to understand the concept of the fees, but there is 1 golden rule - pay the base for getting there, tip as much as you need for prioritizing. Your use case doesn't have to require including transactions in the first free block. In some situations, you might be willing to wait a couple of blocks, but safe on the transaction fee. If you have any follow-up questions, feel free to ask in the comments section below. Stay tuned for the next post. ๐Ÿš€๐Ÿš€๐Ÿš€

ย