Transaction Fees on L2
Understanding Fee Basics
Transaction fees on United Protocol Network work similar to fees on Ethereum. As United Protocol network is a Layer 2 (L2) blockchain, there are new paradigms in the fee structure that cause it to differ from Ethereum's fee.
Since United Protocol Network is constantly perfecting EVM compatibility, dApps can conveniently handle any changes with minor modifications. Let's take a look at the two sources of transaction costs on United Protocol.
The L2 transaction fee for Layer-2 execution
The L1 rollup fee to cover the cost of publishing rollup state roots to L1 (divided equally among users whose transactions were included in the rollup batch)
The L2 Transaction Fee
Just like Ethereum, transactions on United Protocol network have to pay gas for the amount of computation and storage that they use. Every L2 transaction will pay some execution fee, equal to the amount of gas used by the transaction multiplied by the gas price attached to the transaction.
Here's the (simple) math:
ode
L2ExecutionFee = L2GasPrice * L2GasUsed
The amount of L2 gas used depends on the particular transaction that you're trying to send. Thanks to EVM compatibility, transactions typically use approximately the same amount of gas on United Protocol Network as they do on Ethereum. Gas prices fluctuate with time and congestion, but you can always check the current estimated L2 gas price on the public United Protocol dashboard. Also, since gas fees on L2 United Protocol Network are charged in $UT, it means at the same gas price the transaction cost incurred will still be significantly lower than other L2 networks that use $ETH as the gas token.
The L1 Rollup Fee
All the state roots that are generated on L2 as result of transaction execution are published to Ethereum. This step is crucial to the security properties of United Protocol because it means that all of the most up-to-date block data from L2 United Protocol Network that you need to sync a node is always publicly available on L1 Ethereum.
United Protocol publishes rollup states and some necessary transaction data to Ethereum by packaging transactions into batches, and the amount of $ETH spent during this process will be divided among the users whose transactions were included in the batch. The cost-per-user is significantly cheaper than it would be if the transactions were executed on L1. The L1 rollup fee is calculated from the following sub-factors:
The current gas price on Ethereum.
A fixed overhead (auto-adjusted and set into gas oracle)
The scaling factor (currently set to 1)
The $ETH to $UT conversion ratio
Here's the math:
L1RollupFee = L1GasPrice * Overhead * Ratio
The transaction fees incurred by users is calculated and deducted as described below:
A connection is made to the RPC and the
EstimateGas
method is called to calculate the gas cost on L2 (if you use a wallet, such as Metamask, this step will be executed automatically). This is the L2 Transaction Fee.A transaction is signed and submitted
United Protocol node receives the transaction and checks if the account balance is sufficient, including the L2 Transaction Fee and L1 Rollup Fee*.
The transaction is executed successfully, recording your interaction with United Protocol Network.
*Note that there is currently no RPC interface that provides accurate estimates of L1 Rollup Fee, please ensure that wallets have sufficient balance, even though the amount needed is generally very small.
Keep in Mind
Sending Transactions
Since United Protocol supports Ethereum's JSON RPC interface, you can use the eth_gasPrice
method to obtain recommended L2 gas price values. Similarly, you can use eth_estimateGas
to estimate your L2 gas usage.
Gas Price Updates
Gas prices on L2 are set to 0.005 Gwei by default, it will be updated every once in a while with reference to the recent blocks on Ethereum.
EIP-1559 Support
Currently, United Protocol Network does NOT support EIP-1559, so we recommend using legacy structuring for your transactions. The order of transactions is FIFO, and it will be executed based on the sequence (time of receiving) they are received in.
Displaying Fees to Users
You can use the RPC method eth_getTransactionReceipt
to obtain the fees for a particular transaction, where the L1 Rollup Fee portion is listed as the field l1fee
.
Estimating the Total Fee
You can estimate the total fee by combining your estimates for the L2 execution fee and L1 data fee.
Common RPC Errors
Insufficient Funds
Error code: -32000
Error message: invalid transaction: insufficient funds for l1Fee + l2Fee + value
You'll get this error when the account's $XPC balance is not enough to cover the transaction fee and the transfer amount. Check the account balance to ensure that the minimum amount requirements are met.
Gas Price Too Low
Error code: -32000
Error message: gas price too low: X wei, use at least tx.gasPrice = Y wei
This is a custom RPC error that United Protocol network returns when a transaction is rejected because the set gas price is too low. Currently, at least 0.05 Gwei is required, which can be obtained from the GasOracle
contract 0x420000000000000000000000000000000000000F
Gas Price Too High
Error code: -32000
Error message: gas price too high: X wei, use at most tx.gasPrice = Y wei
This is a custom RPC error that United Protocol network returns when a transaction is rejected because the set gas price is too high. Currently limit is set at 200 Gwei.
Last updated