Cover Image for Understanding Gas Consumption: Analyzing Highly Paid Operations on Ethereum and Other Blockchains

Understanding Gas Consumption: Analyzing Highly Paid Operations on Ethereum and Other Blockchains

Analysis
Crypto

Gas fees are fees paid to successfully conduct a transaction on a blockchain platform. They are important parts of these blockchain networks and serve as compensation for validators who use their resources to process and validate transactions.

This article explores the basics of gas fees, examines the most costly operations on Ethereum, and provides a comparative analysis of gas consumption on other prominent blockchains such as Binance Smart Chain (BSC) and Base.

Understanding the complexities of gas consumption is important for developers who aim to optimize their smart contracts and for users who want to minimize transaction costs.

By the end of this article, readers will understand gas consumption across different blockchain networks and the strategies to manage it effectively.

Why People Pay High Gas Fees

Gas fees are the costs paid to perform transactions or execute smart contracts on the blockchain. They serve two main purposes:

  • Incentives for Miners/Validators: Miners and validators receive gas fees as incentives for validating and processing transactions, thereby maintaining the network's security and functionality.

  • Preventing Spam: By charging a fee for each transaction, the network prevents malicious actors from overwhelming it with excessive or unnecessary transactions.

How Gas Fees Work

Gas fees can be broken down into the following components:

  • Gas: Gas is the fee required to conduct a transaction or execute a contract successfully on the Ethereum blockchain platform.

  • Gas Units: This is a measure of the computational power needed to perform operations on the Ethereum blockchain.

  • Gas Price: This refers to the amount of cryptocurrency (e.g., Gwei for Ethereum) that a user is willing to pay per gas unit for a transaction or operation on the blockchain. The price of gas is determined by supply, demand, and network capacity at the time of the transaction.

Factors Affecting Gas Fees

Several factors influence the gas fees on blockchain networks, especially on Ethereum. By having an understanding of these factors, we can manage transaction costs effectively.

Factors include the following :

  • Network Congestion: Network congestion occurs when many users are trying to make transactions at the same time. This increase in activity raises gas fees because users are competing to have their transactions processed quickly.

  • Complexity: The complexity of a transaction or smart contract also influences the amount of gas required. Easy transactions like transferring tokens use less gas than complex transactions like the deployment of smart contracts.

  • Gas Limit: There is a gas limit for each transaction per block. This is the maximum amount of gas that can be used per block. If the total gas consumption of pending transactions exceeds this limit, those with higher gas prices are prioritized, causing higher fees during busy periods.

  • Smart Contract Efficiency: The design and efficiency of smart contracts also impact gas fees. Smart contracts that are well-optimized require less gas to execute, while inefficient contracts are expensive.

Highly Paid Operations on Ethereum

Ethereum is the leading decentralized blockchain platform for smart contracts that makes use of gas to measure the computational effort required for transactions and execution of contracts.

Below is a query that returns top gas consuming calls and events on the Ethereum blockchain from 2024-07-01 to 2024-07-30.

Top calls and events.

Function Details


balanceOf

  • Signature: balanceOf(address)
  • Gas Consumption: 25231034928027
  • Cost (USD): 64719974779.718285
  • Function: The balanceOf function returns the balance of a specific address.
  • Reason for High Gas Consumption: The balanceOf call often involves numerous internal calls, sometimes around 10 for certain contracts. It appears that balanceOf is frequently invoked during write operations, and its common usage in cost-heavy transactions leads to high gas costs being attributed to it.

max

  • Signature: max(uint256,uint256)
  • Gas Consumption: 19709397984544
  • Cost (USD): 182447813.60704768
  • Function: The max function returns the maximum of two given uint256 values. It compares two values and returns the maximum value among them.
  • Reason for High Gas Consumption: Normally inexpensive, the high gas usage might be due to complex interactions with other contract parts that increase gas usage.

min

  • Signature: min(uint256,uint256)
  • Gas Consumption: 19709397984544
  • Cost (USD): 182447813.60704768
  • Function: This function is the opposite of the max function as it returns the minimum of two given uint256 values.
  • Reason for High Gas Consumption: Similar to max, the function might be involved in larger calculations or called multiple times within transactions.

transfer

  • Signature: transfer(address,uint256)
  • Gas Consumption: 15660467214859
  • Cost (USD): 30642811629.941307
  • Function: This function transfers a given amount of tokens from the sender’s account to another address.
  • Reason for High Gas Consumption: High gas consumption for the transfer function may be due to complex token contract implementation, state changes, and additional security checks.

callClaimMintReward

  • Signature: callClaimMintReward(address)
  • Gas Consumption: 12929010612708
  • Cost (USD): 170150247.6614094
  • Function: This function is used to claim minting rewards for a specified address.
  • Reason for High Gas Consumption: Minting processes can use a lot of gas because it involves various checks and balances which contribute to the high gas usage.

powerDown

  • Signature: powerDown()
  • Gas Consumption: 12928930475620
  • Cost (USD): 170149637.39978257
  • Function: The powerDown function is likely used to disable or deactivate certain functionalities within a smart contract, especially in a governance or staking system.
  • Reason for High Gas Consumption: The function may involve multiple or complex operations, such as updating various state variables and interacting with other contracts resulting in high gas consumption.

claimMintRewardAndShare

  • Signature: claimMintRewardAndShare(address,uint256)
  • Gas Consumption: 12093227281162
  • Cost (USD): 133903717.38000655
  • Function: This function claims a minting reward and shares it with a specified address.
  • Reason for High Gas Consumption: Distributing rewards and updating the states of multiple accounts is a complex process and can consume a lot of gas.

claimRank

  • Signature: claimRank(uint256)
  • Gas Consumption: 10810202940109
  • Cost (USD): 69538047.40809974
  • Function: This function is most likely used to claim a rank or position within a system based on certain criteria.
  • Reason for High Gas Consumption: The process may involve extensive calculations or data retrieval to determine the rank, which may result in higher gas usage.

transferFrom

  • Signature: transferFrom(address,address,uint256)
  • Gas Consumption: 10174747845131
  • Cost (USD): 12317007704.06669
  • Function: This function allows a sender to transfer tokens from one account to another after approval.
  • Reason for High Gas Consumption: The function involves extra checks, such as approval and balance verification, which may lead to high gas consumption when compared to a simple transfer.

The gas consumption of Ethereum transactions is significantly impacted by the complexity of the operations performed and the frequency with which functions are called.

To mitigate high gas usage, optimizing smart contracts and minimizing unnecessary function calls is important.

Gas Consumption on Other Blockchains

BNB

Below is a query that returns top gas-consuming calls and events on BSC chain from 2024-07-01 to 2024-07-30.

Analysis of Top Gas Consuming Calls and Events on BNB Chain.

Function Details


slash

  • Signature: slash(address)
  • Gas Consumption: 18446744073709550976
  • Cost (USD): 0
  • Function: The slash function reduces the balance of a specific address, often used in staking or governance protocols to enforce rules or penalize bad actors.
  • Reason for High Gas Consumption: High gas usage might stem from complex logic to verify conditions, update multiple records, or handle state changes securely, making it computationally expensive.

deposit

  • Signature: deposit(address)
  • Gas Consumption: 9223372037085846109
  • Cost (USD): 11114740.506539578
  • Function: The deposit function allows users to deposit tokens or funds to a specified address, often used in financial applications or smart contracts for staking, savings, or liquidity provision.
  • Reason for High Gas Consumption: This function can be gas-intensive due to necessary validation checks, state updates, and interactions with other contracts or storage operations.

balanceOf

  • Signature: balanceOf(address)
  • Gas Consumption: 165338892295799
  • Cost (USD): 6598362569.931131
  • Function: This function returns the balance of tokens held by a specific address, commonly used in BEP-20 and other token standards.
  • Reason for High Gas Consumption: The balanceOf call often involves numerous internal calls, sometimes around 10 for certain contracts. It appears that balanceOf is frequently invoked during write operations, and its common usage in cost-heavy transactions leads to high gas costs being attributed to it.

transfer

  • Signature: transfer(address,uint256)
  • Gas Consumption: 94226635048838
  • Cost (USD): 3048333324.3176413
  • Function: Transfers a specified amount of tokens from the sender’s account to another address.
  • Reason for High Gas Consumption: High usage in decentralized applications (dApps) and frequent token transfers can lead to increased gas consumption.

transferFrom

  • Signature: transferFrom(address,address,uint256)
  • Gas Consumption: 90587402604847
  • Cost (USD): 558571429.1118963
  • Function: Allows a sender to transfer tokens from one account to another, provided they have been approved to do so.
  • Reason for High Gas Consumption: This function requires additional checks (such as approval and balance verification) compared to transfer, which can increase gas consumption.

safeTransferFrom

  • Signature: safeTransferFrom(address,address,uint256)
  • Gas Consumption: 69788385264034
  • Cost (USD): 47636710.82603213
  • Function: This function safely transfers a specific amount of tokens from one address to another, ensuring that the receiving contract is capable of handling BEP-721 tokens.
  • Reason for High Gas Consumption: The safety checks and validation required to ensure the recipient can handle the tokens add to the gas cost.

ownerOf

  • Signature: ownerOf(uint256)
  • Gas Consumption: 60405861461088
  • Cost (USD): 49485845.72234921
  • Function: Returns the owner of a specific BEP-721 token ID.
  • Reason for High Gas Consumption: The function itself is typically low-cost, but high gas consumption may result from frequent calls within a larger application or complex data retrieval processes.

onERC721Received

  • Signature: onERC721Received(address,address,uint256,bytes)
  • Gas Consumption: 56498436129719
  • Cost (USD): 35689364.67503641
  • Function: Handles the receipt of a BEP-721 token, ensuring that the receiving contract can manage BEP-721 tokens.
  • Reason for High Gas Consumption: The validation and handling logic required to manage token receipts securely can be complex, contributing to higher gas usage.

getReserves

  • Signature: getReserves()
  • Gas Consumption: 32055294005348
  • Cost (USD): 1038580480.4862747
  • Function: Returns the reserve amounts of tokens in a liquidity pool, typically used in automated market makers (AMMs) like PancakeSwap.
  • Reason for High Gas Consumption: Retrieving and processing reserve data can be computationally expensive, especially if the pool handles large amounts of data or frequent updates.

The gas consumption of BNB Chain transactions varies based on the complexity of the operations performed and the number of times functions are called within transactions.

BASE

Below is a query that returns top gas consuming calls and events on Base from 2024-07-01 to 2024-07-30.

Top gas consuming calls and events

Function Details


slot0

  • Signature: slot0()
  • Gas Consumption: 2169543679014111
  • Cost (USD): 2586643413.5828342
  • Function: Likely retrieves the first slot of data in a storage structure, commonly used in Uniswap V3-like contracts to fetch pool states.
  • Reason for High Gas Consumption: Accessing and returning multiple pieces of data stored in the contract can be computationally expensive.

liquidity

  • Signature: liquidity()
  • Gas Consumption: 1770630841760160
  • Cost (USD): 1911403451.7775419
  • Function: Retrieves the current liquidity in a pool, used to determine available liquidity for trades.
  • Reason for High Gas Consumption: Calculating and returning liquidity involves reading state variables and aggregating data from multiple sources, which can be gas-intensive.

getReserves

  • Signature: getReserves()
  • Gas Consumption: 1235526747695113
  • Cost (USD): 3280706006.9748497
  • Function: Fetches the reserve amounts of tokens in a liquidity pool.
  • Reason for High Gas Consumption: Retrieving and processing reserve data is computationally expensive, especially if the pool handles large amounts of data or frequent updates.

balanceOf

  • Signature: balanceOf(address)
  • Gas Consumption: 645230811614960
  • Cost (USD): 18593645961.61769
  • Function: Returns the balance of tokens held by a specific address, commonly used in BASE-20 and other token standards.
  • Reason for High Gas Consumption: The balanceOf call often involves numerous internal calls, sometimes around 10 for certain contracts. It appears that balanceOf is frequently invoked during write operations, and its common usage in cost-heavy transactions leads to high gas costs being attributed to it.

tickBitmap

  • Signature: tickBitmap(int16)
  • Gas Consumption: 311326700087010
  • Cost (USD): 491238256.82881993
  • Function: Likely used in Uniswap V3-like contracts, tickBitmap manages liquidity positions at different price points.
  • Reason for High Gas Consumption: Managing and accessing the bitmap can be computationally intensive, especially when handling numerous liquidity positions and price points.

transfer

  • Signature: transfer(address,uint256)
  • Gas Consumption: 288221084368862
  • Cost (USD): 11314124926.597536
  • Function: Transfers a specified amount of tokens from the sender’s account to another address.
  • Reason for High Gas Consumption: High usage in decentralized applications (dApps) and frequent token transfers can lead to increased gas consumption.

transferFrom

  • Signature: transferFrom(address,address,uint256)
  • Gas Consumption: 86188933484916
  • Cost (USD): 2557618574.525107
  • Function: Allows a sender to transfer tokens from one account to another, provided they have been approved to do so.
  • Reason for High Gas Consumption: This function requires additional checks (such as approval and balance verification) compared to a standard transfer, making it more computationally intensive.

getExchange

  • Signature: getExchange()
  • Gas Consumption: 72209647044762
  • Cost (USD): 2348912.339726342
  • Function: Retrieves the exchange rate or the exchange address for a token or pair.
  • Reason for High Gas Consumption: Frequent updates and retrievals of exchange data can make this function gas-intensive.

max

  • Signature: max(uint256,uint256)
  • Gas Consumption: 66014568834582
  • Cost (USD): 1856990.5833117731
  • Function: Computes the maximum of two given unsigned integer values.
  • Reason for High Gas Consumption: Despite its simple logic, it may be part of more complex and repeated operations within larger transactions, leading to significant cumulative gas usage.


Implications for Developers and Users

Here’s a breakdown of their implications for both developers and users:

For Developers:

  • Development Costs: Higher gas fees can increase the cost of development and testing when designing and deploying smart contracts.

  • Gas Optimization: It is important developers write efficient code and also follow best practices to minimize gas usage and also to optimize smart contract code.

  • Scalability: Developers are actively exploring other solutions such as Layer 2 solutions and other protocols to reduce gas fees and improve scalability.

  • Transaction Speed: Since gas fees affect the speed of transactions, developers should appropriate gas limits and prices to balance transaction speed and cost.

For Users:

  • Transaction Costs: High gas fees make it difficult for users to execute transactions or interact with smart contracts, making even smaller transactions unfeasible.

  • Network Congestion: An increase in gas fees during peak times due to high demand can delay transactions, making users wait longer or pay more just to have their transactions confirmed.

  • Alternative Solutions: Users are actively looking for cheaper options, like Layer 2 solutions or other blockchains, to cut down on transaction costs.

Conclusion

Having an understanding of the operations that incur the highest fees is important for optimizing blockchain usage. High gas fees on Ethereum, for example, are due to complex operations and high network congestion. People will pay these high fees for operations that are considered high-value, such as complex smart contract interactions or essential transactions.

By analyzing the most expensive operations, developers can reduce costs by optimizing their smart contracts. This also helps users make informed decisions when conducting transactions and explore alternatives like Binance Smart Chain and Polygon, which offer lower gas fees to reduce costs.

Subscribe to our newsletter

Subscribe and never miss any updates related to our APIs, new developments & latest news etc. Our newsletter is sent once a week on Monday.