# L1 Data Fee Calculation (Fjord)

This page describes how to calculate the L1 data fee for a specific transaction on a Zircuit network post Fjord upgrade.

#### Retrieve the parameters

To perform the calculation the following parameters are needed:

* L1 base fee
* L1 base fee scalar
* L1 blob base fee
* L1 blob base fee scalar

They are available by calling the Gas Price Oracle smart contract predeployed on every Zircuit network on this address: `0x420000000000000000000000000000000000000F`

To retrieve them we can use Foundry's cast. You will need the block number in which the transaction was included to retrieve the parameters from the right point in time. You will also need a valid RPC url. For example you'll find the RPC urls on this page:

{% content-ref url="/pages/fEv1Wrfl0hPzbT380Xlr" %}
[RPCs](/infra/rpcs.md)
{% endcontent-ref %}

L1 base fee:

```sh
cast call 0x420000000000000000000000000000000000000F "l1BaseFee()(uint256)" --rpc-url $RPC_URL --block $BLOCK_NUMBER
```

L1 base fee scalar:

```sh
cast call 0x420000000000000000000000000000000000000F "baseFeeScalar()(uint256)" --rpc-url $RPC_URL --block $BLOCK_NUMBER
```

L1 blob base fee:

```sh
cast call 0x420000000000000000000000000000000000000F "blobBaseFee()(uint256)" --rpc-url $RPC_URL --block $BLOCK_NUMBER
```

L1 blob base fee scalar:

```sh
cast call 0x420000000000000000000000000000000000000F "blobBaseFeeScalar()(uint256)" --rpc-url $RPC_URL --block $BLOCK_NUMBER
```

Get the raw RLP-encoded signed transaction:

```sh
cast tx $TX_HASH --rpc-url $RPC_URL --raw
```

| intercept          | -42\_585\_600 | Linear regression intercept (scaled by 1e6)   |
| ------------------ | ------------- | --------------------------------------------- |
| fastlzCoef         | 836\_500      | Linear regression coefficient (scaled by 1e6) |
| minTransactionSize | 100           | Minimum transaction size in bytes             |

[fastLzSize](https://github.com/zircuit-labs/l2-geth-public/blob/main/core/types/rollup_cost.go#L684-L760) can be calculated using the bytes represented by the raw RLP-encoded signed transaction as the parameter.

Now that you have all the info you need, you can just apply the following formula:

```
estimatedSizeScaled = max(minTransactionSize * 1e6, intercept + fastlzCoef*fastlzSize)
```

<pre><code><strong>1FeeScaled = baseFeeScalar * l1BaseFee * 16 + blobFeeScalar * l1BlobBaseFee
</strong></code></pre>

```
l1Cost = estimatedSizeScaled * l1FeeScaled / 1e12
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.zircuit.com/info/architecture/gas-pricing-and-transaction-fees/l1-data-fee-calculation-fjord.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
