๐Ÿ’ต

Fees on L2

ย 
๐Ÿ’ก
The L1 Fee tends to be higher than the L2 Fee.
L2 Execution Fee
Every L2 transaction pays an execution fee:
The amount of L2 gas used depends on the type of transaction you are trying to get processed. Because of EVM Equivalence, transactions typically use around the same amount of gas as they do on Ethereum.
ย 
๐Ÿ’ก
The L2 gas price is currently set to 0.001 gwei.
L1 Data Fee
Transactions on Optimism are published to Ethereum.
Users on Optimism have to pay the cost of submitting their transactions to Ethereum, this is called the L1 data fee.
The L1 data fee typically dominates the total cost of a transaction on Optimism.
ย 
This fee is based on 4 factors:
  1. Current L1 gas price
  1. L1 Data Gas (L1 gas cost to publish the transaction) [scales roughly with the size of the tx in bytes]
  1. Fixed overhead cost (denominated in gas โ†’ current set to 2100 )
  1. Dynamic overhead cost (scales the L1 fee paid by a fixed number โ†’ currently set to 1 )
1) L1 gas price
This gas price can be found by using any gas price oracle for L1 (see https://www.gastly.tools/ for example)
2) L1 data gas amount
This describes the gas required on L1 to publish the transaction. This is based on the transaction length as well as the byte value (whether it is zero or a different value) for each byte.
The amount can be computed with the following formula:
3) Fixed overhead cost
This value is set in the Gas Price Oracle contract under the overhead storage variable.
Simply read the overhead value in the contract. The value is currently set to 2100.
4) Dynamic overhead cost
This value is set in the Gas Price Oracle contract under the scalar storage variable.
To get the actual value, you must divide the scalar variable value by 1 million.
The value is therefore currently set to 1.
ย 
With these 4 values, we can calculate the L1 Data Fee.
Formula for L1 Data Fee
ย 
Estimating total fee of users
Estimating the L2 execution fee
L2 execution fee is determined by multiplying the gas price by the gas limit set (this was shown above):
ย 
Estimating L1 data fee
There are 2 ways you can get estimate information about this cost.
  1. Use the Optimism SDK (https://sdk.optimism.io/)
  1. Use the GasPriceOracle smart contract deployed on L2
      • call GasPriceOracle.getL1Fee(<unsigned RLP encoded transaction>)
ย 
Estimating Total fee
ย 
ย 
Extra interesting info
Sending transactions
When sending a transaction, you should provide a gas price greater than or equal to the current L2 gas price. As with Ethereum, you do this with an RPC method eth_gasPrice . Similarly, you should set your gas limit in the same way you would on Ethereum (via eth_estimateGas ).
๐Ÿ’ต

Fees on L2

ย 
๐Ÿ’ก
The L1 Fee tends to be higher than the L2 Fee.
L2 Execution Fee
Every L2 transaction pays an execution fee:
The amount of L2 gas used depends on the type of transaction you are trying to get processed. Because of EVM Equivalence, transactions typically use around the same amount of gas as they do on Ethereum.
ย 
๐Ÿ’ก
The L2 gas price is currently set to 0.001 gwei.
L1 Data Fee
Transactions on Optimism are published to Ethereum.
Users on Optimism have to pay the cost of submitting their transactions to Ethereum, this is called the L1 data fee.
The L1 data fee typically dominates the total cost of a transaction on Optimism.
ย 
This fee is based on 4 factors:
  1. Current L1 gas price
  1. L1 Data Gas (L1 gas cost to publish the transaction) [scales roughly with the size of the tx in bytes]
  1. Fixed overhead cost (denominated in gas โ†’ current set to 2100 )
  1. Dynamic overhead cost (scales the L1 fee paid by a fixed number โ†’ currently set to 1 )
1) L1 gas price
This gas price can be found by using any gas price oracle for L1 (see https://www.gastly.tools/ for example)
2) L1 data gas amount
This describes the gas required on L1 to publish the transaction. This is based on the transaction length as well as the byte value (whether it is zero or a different value) for each byte.
The amount can be computed with the following formula:
3) Fixed overhead cost
This value is set in the Gas Price Oracle contract under the overhead storage variable.
Simply read the overhead value in the contract. The value is currently set to 2100.
4) Dynamic overhead cost
This value is set in the Gas Price Oracle contract under the scalar storage variable.
To get the actual value, you must divide the scalar variable value by 1 million.
The value is therefore currently set to 1.
ย 
With these 4 values, we can calculate the L1 Data Fee.
Formula for L1 Data Fee
ย 
Estimating total fee of users
Estimating the L2 execution fee
L2 execution fee is determined by multiplying the gas price by the gas limit set (this was shown above):
ย 
Estimating L1 data fee
There are 2 ways you can get estimate information about this cost.
  1. Use the Optimism SDK (https://sdk.optimism.io/)
  1. Use the GasPriceOracle smart contract deployed on L2
      • call GasPriceOracle.getL1Fee(<unsigned RLP encoded transaction>)
ย 
Estimating Total fee
ย 
ย 
Extra interesting info
Sending transactions
When sending a transaction, you should provide a gas price greater than or equal to the current L2 gas price. As with Ethereum, you do this with an RPC method eth_gasPrice . Similarly, you should set your gas limit in the same way you would on Ethereum (via eth_estimateGas ).