Skip to main content

What is Gas? How are Gas Limit, Gas Price and Network Fee calculated?

U
Written by UKey Wallet

Crypto Concepts & FAQs

Gas A unit used by Ethereum and many EVM compatible networks to measure the computing resources required for on-chain operations. Transfers, token authorization, exchange or calling smart contracts will consume a certain amount of Gas; The network fees users pay for these resources are called Gas Fee.

In the basic EVM fee model, the following simplified formula can be used to understand:

Gas Fee (network fee) = Gas Used (actual usage) × Effective Gas Price (actual unit price)

Applicable boundaries:Gas is not an independent token, nor is it a fee model used by all blockchains. Gas fees are usually paid in native assets of the current network; Some Layer 2 or specialty networks may also have additional data or protocol charges.

Why is Gas needed?

Blockchain nodes need to perform calculations, read and write status, and save transaction results. Gas provides a unified measurement method for resource consumption of different operations, and also limits the maximum amount of work that can be performed in a single transaction. Avoid infinite loops or a large number of costless requests that occupy network resources.

The more complex the transaction, the more contract logic usually needs to be executed, and the higher the Gas Used may be. Therefore, Gas Fee is mainly affected by Operational complexity and The unit price at that time The impact does not simply depend on the transfer amount.

What is the difference between Gas Used, Gas Limit, Gas Price and Gas Fee?

concept

meaning

Gas Used

The amount of gas consumed when the transaction is actually executed

Gas Limit

The upper limit of gas allowed to be consumed by this transaction

Gas Price

The price per unit of Gas, often expressed in Gwei

Gas Fee

The final network fee incurred by the transaction

1 Gwei = 0.000000001 ETH. Gas Limit is not a predetermined final consumption: when a transaction is completed normally, only actual usage is billed, and unused limits are not charged. If the upper limit is set too low, Execution may roll back due to insufficient gas, but the computing resources that have been consumed may still incur charges.

Trading Gas Limit with Block Gas Limit It's not the same concept either. The former limits the maximum usage of a single transaction; the latter limits the total amount of calculations that can be accommodated in a block, mainly belonging to network protocol layer parameters.

How do EIP-1559 fee parameters work?

Networks using the EIP-1559 fee mechanism typically display the following parameters:

  • Base Fee:The protocol's base unit price is calculated based on block usage. On the Ethereum mainnet, this part of the fee will be destroyed.

  • Priority Fee:The priority fee paid to validators is used to express the desire for transactions to be included in blocks faster, but higher settings do not guarantee that transactions will be confirmed immediately.

  • Max Fee Per Gas:The maximum amount a user is allowed to pay per unit of gas. The actual unit price will not exceed this upper limit.

The "maximum network fee" displayed by the wallet is usually calculated by the Gas Limit and the maximum unit price. It is used to show the possible upper limit of fees and is not equal to the final amount deducted. Actual settlement depends on transaction usage, effective unit price, and the corresponding network's fee rules. Instructions for setting up fees are found in UKey Wallet How do I manage UKey Wallet transaction fees? 》.

Why may a failed transaction still generate gas fees?

The key is whether the transaction has been included in the block and executed by the network:

situation

Are there usually on-chain fees?

The transaction was rejected locally, or was never successfully broadcast and included in the block

Usually not

The transaction has been included in the block, but the contract conditions are not met, the gas is insufficient, or the execution is rolled back.

Usually the gas that has been consumed will be charged

The failure of the chain result does not mean that the node is not working. The validator has already processed the transaction and performed the corresponding calculations, so the resources consumed during execution may still be charged.

What operations require Gas? Who pays?

Operation

Is Gas usually required?

Connect wallet, read public address or balance

No, because the on-chain state is not modified.

Ordinary message signature

The signature itself is not required; if the signature is subsequently submitted to the chain, the submitting party still needs to pay the fee

Transfer, token authorization, redemption, minting or revocation of authorization

Required because the on-chain state will be modified

The permissions and risks of connecting wallets, message signatures, transaction signatures, and token authorized representatives are different. Whether the operation is safe cannot be judged solely by "whether gas is required." For detailed differences, see"What is the difference between connecting wallets, message signing, transaction signing and token authorization?" 》.

Even if the account holds tokens such as USDT and USDC, it is usually necessary to retain the native assets of the current network to pay Gas Fee. If there are insufficient native assets, no matter how large the token balance is, it may not be possible to initiate on-chain operations.

Network fees are determined by protocol rules and current on-chain status. The wallet client is responsible for estimating and constructing fee parameters, and the hardware wallet is responsible for displaying the transaction information it can parse and signing after the user confirms; The hardware device itself will not judge whether the cost is reasonable for the user. See the signature process《UKey How does the hardware wallet ensure the security of transaction signatures? 》.

FAQ

The balance is equal to the transfer amount, why is it still prompted that the balance is insufficient?

The account also requires network fees. The maximum amount that can be sent is usually smaller than the native asset balance, requiring room for expected fees.

Why do different DApps perform similar operations but still have different fees?

Different DApps may call different contracts, routes or steps, and the actual calculation and state writing amounts are different, so the Gas Used will also be different.

Why is the "maximum fee" higher than the final deduction?

Maximum charges reflect allowed usage and unit price caps. After the transaction is completed, the settlement is usually based on actual usage and effective unit price; some networks will also calculate data fees separately.

Why do I have to pay to expedite or cancel a transaction?

Acceleration or cancellation typically requires the submission of another on-chain transaction, thus still tying up network resources and incurring fees. For detailed instructions, see"How do I accelerate or cancel a transaction?" 》.

Summarize:Gas measures the computing usage of on-chain operations, Gas Price represents the unit price, Gas Limit is the upper limit of allowed usage, and Gas Fee is the final network fee. Understanding these concepts will help determine common problems such as fee caps, transaction failure deductions, and insufficient native assets.

Did this answer your question?