How do network fees work on PGN?
Since PGN is built using the OP Stack, we directly adopted their gas/fee structure. These fees are very similar to fees on the Ethereum L1 network, but there are some key differences that you need to understand about L2s built on the OP Stack.
Overall, since your PGN transactions are submitted as part of a “rollup” back to the L1, the fees are substantially less to settle compared to settling directly on Ethereum mainnet.
Learn more by reading the OP Stack transaction fees documentation (opens in a new tab).
Fee breakdown
Every PGN transaction consists of two costs:
- An L2 execution fee
- An L1 data fee
The total PGN transaction fee is a simple equation adding these two fees:
transaction_fee = l2_execution_fee + l1_data_fee
L2 execution fee
The L2 execution fee is the cost to execute your transaction on the L2.
Just like on Ethereum, transactions on PGN have to pay gas for the amount of computation and storage that they use. Every L2 transaction will pay an execution fee equal to the amount of gas used by the transaction multiplied by the gas price attached to the transaction.
This fee is based on three factors:
- The L2 base fee (opens in a new tab) is charged for each unit of gas that a transaction uses. It is the same base fee for each transaction in the block, and is determined by formulas based on the base fee of the previous block and how full that block was. You can find the current L2 base fee on the Optimism gas tracker dashboard (opens in a new tab).
- The priority fee (opens in a new tab) is the amount that a user pays. To enable your users to select a priority fee, you can build a priority fee estimator (opens in a new tab). If you already have estimating code you use for L1 Ethereum, you can just use that.
- The amount of L2 gas used depends on the transaction you are sending. With EVM equivalence, the L2 transactions use approximately the same amount of gas as they would on Ethereum.
You can calculate the L2 execution fee using the following equation:
transaction_gas_price = l2_base_fee + l2_priority_fee
l2_execution_fee = transaction_gas_price * l2_gas_used
L1 data fee
The L1 data fee is the estimated cost to publish the transaction on the L1. Typically the L1 data fee is higher than the L2 execution fee. This fee is the primary discrepancy between PGN and Ethereum.
This fee is based on four factors:
- The gas cost to publish the transaction to Ethereum. This scales roughly with the size of the transaction in bytes. (
tx_data_gas
) - The current gas price on Ethereum. (
l1_gas_price
) - A fixed overhead cost denominated in gas. (
fixed_overhead
) - A dynamic overhead cost which scales the L1 fee paid by a fixed number. (
dynamic_overhead
)
You can calculate the L1 data fee using the following equation:
tx_data_gas = count_zero_bytes(tx_data) * 4 + count_non_zero_bytes(tx_data) * 16
l1_data_fee = l1_gas_price * (tx_data_gas + fixed_overhead) * dynamic_overhead
Fee estimation tooling
While you can use the above formulas to calculate the gas cost of transactions, you can also use the Optimism SDK (opens in a new tab) or the Optimism Fee Estimation tool (opens in a new tab) to help generate these estimations for you. OP Stack fee estimation will soon be natively available in your preferred Ethereum tools.