In case of L1, the transaction fee is typically calculated as the product of gas price and gas usage, i.e.,

txFee = gasPrice * gasUsage

One such example can be seen in this transaction.

enter image description here

In which the Transaction Fee is calculated as:

Gas Price: 0.000000003047776709 ETH
Gas Usage:  23681  WEI => 0.000000000000023681 ETH

0.000000003047776709 * 0.000000000000023681 = 0.000072174400245829 ETH

I've gone through this article, which explains how the calculation of transaction costs being done on L2. But, I'm still unable to get how the calculations would be done for tx_data_gas, and then the final fee being calculated as:

txFee = data_fee + execution_fee

Can anyone please explain how this calculation is being done in real-time, basically in context of an actual transaction (on Base-Sepolia i.e., a Layer-2 network) corresponding to the contract function call (i.e., exactly similar to what's being done on L1 in the above transaction)?

As we can see, there are some extra terminologies being introduced on any L2 Explorer, like:

enter image description here

So, how these extra values can be calculated (using some library like ethers.js or web3.js) and how are they contributing towards the calculation of overall transaction fee?


2 Answers 2


Ethereum uses EIP-1559 to calculate gas fees, which is explained here: https://eips.ethereum.org/EIPS/eip-1559

EIP-1559 went live on August 5th, 2021, with a hard fork known as the London fork.

Polygon, an L2, rolled out the same EIP-1559 gas calculation method in 2022, on January 18, at 3 a.m. UTC. So Polygon calculates the base gas fee in the same way that Ethereum does.

You'd have to look at each chain to find out how they implement gas fee calculations.

  • 1
    Thanks a lot for the response, Keir. So, the L1 factors that we see on any L2 transaction like this, their values vary from chain to chain (depending on the corresponding rollup project and its stack like OP Stack and OVM, Arbitrum, StarkNet, zkSync Era, Linea, Scroll). But, is there a way to fetch those values so as to estimate the transaction cost, using some library, instead of manually checking the network docs? Apr 5 at 23:35


Programmatically I haven't a clue as I've never used an L2, however you can determine what your tx would cost on ETH and then and multiply it by the ratio of L2 average gas to ETH average gas.

Whatever L2.info is using would be how you could determine them exactly precisely in realtime, however that's beyond my ability to scope out at the present time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.