How to estimate gas in Arbitrum
Head over to the Stylus gas docs for Stylus-specific guidance.
This how-to covers how gas operates in Arbitrum, how it's calculated, and how to estimate it before submitting transactions. For a deeper understanding of the underlying pricing mechanisms, see the Gas and Fees concept page.
Quick start: use eth_estimateGas
If you don't need to understand the formula, you can rely on the standard gas estimation process. Call an Arbitrum node's eth_estimateGas RPC, which returns a gas limit sufficient to cover the entire transaction fee at the current child chain gas price.
Multiplying the value from eth_estimateGas by the child chain gas price gives you the total ETH required for the transaction to succeed. Note that for a given operation, the eth_estimateGas value may vary over time as the parent chain calldata price fluctuates.
Alternatively, call NodeInterface.gasEstimateComponents() and use the first result (gasEstimate) as your gas limit. Multiply by the third result (baseFee) to get the total cost.
Note that when working with parent to child chain messages (also known as retryable tickets), you can use the function ParentToChildMessageGasEstimator.estimateAll() of the Arbitrum SDK or NodeInterface.estimateRetryableTicket() to get all the gas information needed to send a successful transaction.
The fee formula
The model below explains a two-dimensional fee model that captures both L1 and L2 costs. However, it is important to note that users will see a single fee—the L2 cost with the L1 fee "baked-in." This differs from other Rollups.
Arbitrum converts L1 calldata costs into equivalent L2 gas, so the user sees a single fee rather than two (as explained in the model below). The formula detailed below is precisely how it is calculated—but just remember it is shown as a single fee to the user.
Arbitrum uses a two-dimensional fee model where a transaction's total fee has two components: child chain execution costs and parent chain data posting costs. The total transaction fee is:
Transaction fees (TXFEES) = L2 Gas Price (P) * Gas Limit (G)
The gas limit includes the gas for child chain computation plus an additional buffer to cover the parent chain gas the Sequencer pays when posting the batch:
Gas Limit (G) = Gas used on L2 (L2G) + Extra Buffer for L1 cost (B)
The buffer accounts for the cost of posting the transaction (batched and compressed) on the parent chain. The parent chain estimated posting cost is:
L1 Estimated Cost (L1C) = L1 price per byte of data (L1P) * Size of data to be posted in bytes (L1S)
Where:
- L1P estimates the current parent chain price per byte of data, dynamically adjusted by the child chain over time
- L1S estimates how many bytes the transaction will occupy in the batch by compressing it with Brotli
The buffer converts this cost into child chain gas units:
Extra Buffer (B) = L1 Estimated Cost (L1C) / L2 Gas Price (P)
Combining everything:
TXFEES = P * (L2G + ((L1P * L1S) / P))