> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abs.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Gas Fees

> Learn how Abstract differs from Ethereum's EVM opcodes.

Abstract’s gas fees depend on the fluctuating
[gas prices](https://ethereum.org/en/developers/docs/gas/) on Ethereum. As mentioned in
the [transaction lifecycle](/how-abstract-works/architecture/transaction-lifecycle)
section, Abstract posts state diffs *(as well as compressed contract bytecode)* to Ethereum
in the form of [blobs](https://www.eip4844.com/).

In addition to the cost of posting blobs, there are costs associated with generating
ZK proofs for batches and committing & verifying these proofs on Ethereum.

To fairly distribute
these costs among L2 transactions, gas fees on Abstract are charged proportionally
to how close a transaction brought a batch to being **sealed** (i.e. full).

## Components

Fees on Abstract therefore consist of both **off-chain** and **onchain** components:

1. **Offchain Fee**:
   * Fixed cost (approximately \$0.001 per transaction).
   * Covers L2 state storage and zero-knowledge [proof generation](/how-abstract-works/architecture/components/prover-and-verifier#proof-generation).
   * Independent of transaction complexity.
2. **Onchain Fee**:
   * Variable cost (influenced by Ethereum gas prices).
   * Covers [proof verification](/how-abstract-works/architecture/components/prover-and-verifier#proof-verification) and [publishing state](/how-abstract-works/architecture/transaction-lifecycle) on Ethereum.

## Differences from Ethereum

| Aspect                  | Ethereum                                                   | Abstract                                                                                 |
| ----------------------- | ---------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| **Fee Composition**     | Entirely onchain, consisting of base fee and priority fee. | Split between offchain (fixed) and onchain (variable) components.                        |
| **Pricing Model**       | Dynamic, congestion-based model for base fee.              | Fixed offchain component with a variable onchain part influenced by Ethereum gas prices. |
| **Data Efficiency**     | Publishes full transaction data.                           | Publishes only state deltas, significantly reducing onchain data and costs.              |
| **Resource Allocation** | Each transaction independently consumes gas.               | Transactions share batch overhead, potentially leading to cost optimizations.            |
| **Opcode Pricing**      | Each opcode has a specific gas cost.                       | Most opcodes have similar gas costs, simplifying estimation.                             |
| **Refund Handling**     | Limited refund capabilities.                               | Smarter refund system for unused resources and overpayments.                             |

## Gas Refunds

You may notice that a portion of gas fees are **refunded** for transactions on Abstract. This
is because accounts don’t have access to the `block.baseFee` context variable;
and have no way to know the exact fee to pay for a transaction.

Instead, the following steps occur to refund accounts for any excess funds spent on a transaction:

<Steps>
  <Step title="Block overhead fee deduction">
    Upfront, the block’s processing overhead cost is deducted.
  </Step>

  <Step title="Gas price calculation">
    The gas price for the transaction is then calculated according to the
    [EIP-1559](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md)
    rules.
  </Step>

  <Step title="Gas price calculation">
    The **maximum** amount of gas (gas limit) for the transaction is deducted from
    the account by having the account typically send `tx.maxFeePerGas *
          tx.gasLimit`. The transaction is then executed (see [transaction
    flow](/how-abstract-works/native-account-abstraction/transaction-flow)).
  </Step>

  <Step title="Gas refund">
    Since the account may have overpaid for the transaction (as they are sending the maximum fee possible), the bootloader
    **refunds** the account any excess funds that were not spent on the transaction.
  </Step>
</Steps>

## Transaction Gas Fields

When creating a transaction on Abstract, you can set the `gas_per_pubdata_limit` value
to configure the maximum gas price that can be charged per byte of pubdata (data posted to Ethereum in the form of blobs).
The default value for this parameter is `50000`.

## Calculate Gas Fees

1. **Base Fee Determination**: When a batch opens, Abstract calculates the FAIR\_GAS\_PER\_PUBDATA\_BYTE (EPf):

```
EPf = ⌈(Ef) / (L1_P * L1_PUB)⌉
```

* Ef is the "fair" gas price in ETH
* L1\_P is the price for L1 gas in ETH
* L1\_PUB is the number of L1 gas needed for a single pubdata byte

2. **Overhead Calculation**: For each transaction, Abstract calculates several types of overhead:

The total overhead is the maximum of these:

* Slot overhead (SO)
* Memory overhead (MO)
* Execution overhead (EAO)
* `O(tx) = max(SO, MO(tx), EAO(tx))`

3. **Gas Limit Estimation**: When estimating a transaction, the server returns:

```
tx.gasLimit = tx.actualGasLimit + overhead_gas(tx)
```

4. **Actual Fee Calculation**: The actual fee a user pays is:

```
ActualFee = gasSpent * gasPrice
```

5. **Fair Fee Calculation**: Abstract calculates a "fair fee":

```
FairFee = Ef * tx.computationalGas + EPf * pubdataUsed
```

6. **Refund Calculation**: If the actual fee exceeds the fair fee, a refund is issued:

```
Refund = (ActualFee - FairFee) / Base
```
