Model L2 fee market and gas token
An L2 transaction pays two different markets at once — the L2's own EIP-1559 execution fee and a pass-through of the cost of publishing the data to L1 — and quoting a single number hides which one moved.
Procedure
Identify the fee model. OP Stack charges
L2 gas × L2 base feeplus an L1 data fee computed by theGasPriceOraclefrom the L1 base fee (or blob base fee), two scalars, and the signed transaction's RLP size. Arbitrum uses an L2 base fee plus an L1 calldata cost read from its own precompile/GasPriceOracle. zkSync and others differ again.Read the oracle inputs on OP Stack:
cast call 0x420000000000000000000000000000000000000F "l1BaseFee()(uint256)" --rpc-url $L2RPC cast call 0x420000000000000000000000000000000000000F "blobBaseFee()(uint256)" --rpc-url $L2RPC cast call 0x420000000000000000000000000000000000000F "baseFeeScalar()(uint32)" --rpc-url $L2RPC cast call 0x420000000000000000000000000000000000000F "decimals()(uint256)" --rpc-url $L2RPCGet the L1 data fee for a specific transaction directly rather than re-deriving the formula:
cast call 0x420000000000000000000000000000000000000F "getL1Fee(bytes)(uint256)" $SIGNED_TX_RLP --rpc-url $L2RPCCompute the L2 execution fee:
gasUsed × effectiveGasPrice, where the base fee adjusts per block toward a target gas usage like any EIP-1559 chain. Read the current base fee:cast block latest --rpc-url $L2RPC --field baseFeePerGasSum:
total = l2_execution_gas × base_fee + getL1Fee(signed_rlp). Note the L1 data fee is charged in the L2 gas token, so a rising L1 reveals itself as a rising L2 fee even with idle L2 blocks.For estimation, use the node's
eth_estimateGasand the oracle's fee, and inflate the L1 component for a safety margin because the RLP size is fixed but the L1 base fee at inclusion is not:cast estimate $TO --rpc-url $L2RPC --value $VReport the decomposition explicitly (L2 portion in gwei, L1 portion in the gas token and its USD equivalent), never a single blended figure.
Pitfalls
- Assuming L2 gas is cheap so the fee is cheap; on OP Stack the L1 data fee can dominate for calldata-heavy transactions.
- Reading
l1BaseFeeafter an L1 spike but estimating against a cached value, under-quoting by a lot. - Mixing the L1 blob base fee and the L1 execution base fee — post-Dencun chains scale by the blob fee, not the execution fee, and using the wrong one is off by orders of magnitude.
- Forgetting the
decimals()/scalar scaling when hand-deriving; usegetL1Feeinstead. - Treating the L2 gas token as always ETH; some chains use their own token, and the fee is then denominated in that token.
Verification
cast call 0x420000000000000000000000000000000000000F "getL1Fee(bytes)(uint256)" $RLP --rpc-url $L2RPC
cast block latest --rpc-url $L2RPC --field baseFeePerGas
# then compare against the receipt's effectiveGasPrice × gasUsed on a landed tx
Report the L2 execution fee, the L1 data fee, their ratio, and the oracle values used, each traced to the call that produced it.