Fee Scheme OVM 2.0
Fee scheme in Habtor Network under OVM 2.0
Fee Scheme in OVM 2.0
This page refers to the new state of Habtor Network after the OVM 2.0 update.
You can see how the fee is calculated and deducted here.
For backend developers:
You must send your transaction with a tx.gasPrice that is greater than or equal to the sequencer's l2 gas price. You can read this value from the Sequencer by querying the
OVM_GasPriceOraclecontract (OVM_GasPriceOracle.gasPrice) or by simply making an RPC query toeth_gasPrice. If you don't specify yourgasPriceas an override when sending a transaction ,ethersby default querieseth_gasPricewhich will return the lowest acceptable L2 gas price.You can set your
tx.gasLimithowever you might normally set it (e.g. viaeth_estimateGas). You can expect that gas usage for transactions on Habtor network will be identical to gas usage on BSC mainnet.We recommend building error handling around the
Fee too Lowerror detailed below, to allow users to re-calculate theirtx.gasPriceand resend their transaction if fees spike.
For Frontend and Wallet developers:
We recommend displaying an estimated fee to users via the following math. For example, calculating the L1 fee for sending a USDC transfer:
import { getContractFactory, predeploys }from '@eth-optimism/contracts'
import { ethers } from 'ethers'
const OVM_GasPriceOracle = getContractFactory('OVM_GasPriceOracle')
.attach(predeploys.OVM_GasPriceOracle)
const WETH = new Contract(...) //Contract with no signer
const unsignedTx = WETH.populateTransaction.transfer(to, amount)
const signedTx = serialize({
nonce: parseInt(unsignedTx.nonce.toString(10), 10),
value: unsignedTx.value,
gasPrice: unsignedTx.gasPrice,
gasLimit: unsignedTx.gasLimit,
to: unsignedTx.to,
data: unsignedTx.data,
})
const l1FeeInWei = await OVM_GasPriceOracle.getL1Fee(signedTx)You should not allow users to change their
tx.gasPriceIf they lower it, their transaction will revert
If they increase it, they will still have their tx immediately included, but will have overpaid.
Users are welcome to change their
tx.gasLimitas it functions exactly like on L1. You can show the math :Or you can hide the formula behind a tooltip or an "Advanced" section and just display the estimated fee to users
For MVP: don't need to display the L1 or L2 fee
Might need to regularly refresh the L1 Fee and L2 Fee estimate to ensure it is accurate at the time the user sends it (e.g. they get the fee quote and leave for 12 hours then come back)
Ideas: If the L1 fee quoted is > X minutes old, could display a warning next to it
Common RPC Errors
There are three common errors that would cause your transaction to be rejected
Insufficient funds
If you are trying to send a transaction and you do not have enough BNB to pay for that L2 fee + the L1 Fee charged, your transaction will be rejected.
Error code:
-32000Error message:
invalid transaction: insufficient funds for l1Fee + l2Fee + value
Gas Price to low
Error code:
-32000Error message:
gas price too low: 1000 wei, use at least tx.gasPrice = X weiwherexis l2GasPrice.Note: values in this error message vary based on the tx sent and current L2 gas prices
It is recommended to build in error handling for this. If a user's transaction is rejected at this level, just set a new
tx.gasPricevia RPC query ateth_gasPriceor by callingOVM_GasPriceOracle.gasPrice
Fee too large
Error code:
-32000Error message:
gas price too high: 1000000000000000 wei, use at most tx.gasPrice = Y weiwherexis 3*l2GasPrice.When the
tx.gasPriceprovided is ≥3x the expectedtx.gasPrice, you will get this error^, note this is a runtime config option and is subject to change
Last updated