Average Gas Used
This statistic shows the average gas consumed per gas-consuming transaction on the Hedera network within a given time period. It can be broken down by transaction type to isolate gas usage for contract calls, Ethereum transactions, and contract creations.
To access this Hedera network statistic (and others) via Hgraph's GraphQL & REST APIs, create a free account at app.hgraph.com.
Hedera Stat Names:
avg_gas_used- Average gas consumed per gas-consuming transaction (all types)avg_gas_used_contract_call- Average gas consumed per contract call transaction (type 7)avg_gas_used_ethereum_tx- Average gas consumed per Ethereum transaction (type 50)avg_gas_used_contract_create- Average gas consumed per contract creation transaction (type 8)
Methodology
Common Calculation Logic
All four metrics share the same core calculation logic:
- Query the
contract_resulttable for transactions within the specified time window (start_timestamptoend_timestamp). - Filter for successful transactions where
transaction_result = 22(success). - Exclude zero-gas results by requiring
gas_used IS NOT NULLandgas_used > 0. - Calculate the average of
gas_usedacross all qualifying transactions, grouped by the requested time period usingdate_trunc(period). - Return the result as a time-series with each row representing one period's average gas consumption.
The type-specific metrics apply additional filters on top of this shared logic.
Average Gas Used (All Types)
The avg_gas_used metric calculates the average gas consumed across all gas-consuming transactions, regardless of transaction type. This provides a broad view of gas usage on the network.
Since it does not filter by transaction type, it queries the contract_result table directly without joining to the transaction table. This makes it the most inclusive metric, covering contract calls, Ethereum transactions, contract creations, and any other gas-consuming operations.
Average Gas Used by Transaction Type
The three type-specific metrics extend the common logic by joining the contract_result table to the transaction table and filtering on transaction.type. This isolates gas usage to a specific category of EVM activity. See Hedera Mirror Node transaction codes for all type definitions.
Contract Call (Type 7)
The avg_gas_used_contract_call metric filters for transaction.type = 7 (ContractCall). These are direct calls to existing smart contracts on the network, such as executing a function, transferring tokens via a contract, or updating contract state.
Ethereum Transaction (Type 50)
The avg_gas_used_ethereum_tx metric filters for transaction.type = 50 (EthereumTransaction). These are transactions submitted via the Ethereum-compatible JSON-RPC relay. They tend to show higher average gas usage than native contract calls because relay-submitted transactions are often more complex operations (DeFi interactions, multi-step swaps, etc.).
Contract Create (Type 8)
The avg_gas_used_contract_create metric filters for transaction.type = 8 (ContractCreateInstance). These are contract deployment transactions. They consume the most gas of any transaction type since deploying a new contract involves storing bytecode on-chain. This metric may have sparse data because contract deployments are less frequent than contract calls.
GraphQL API Examples
Test out these queries using our developer playground.
Note: The
totalfield represents the average gas consumed in gas units (no conversion needed). For example, atotalof49423means an average of 49,423 gas units per qualifying transaction in that period.
Fetch current average gas used (hourly)
query AvgGasUsedHourly {
ecosystem_metric(
order_by: { end_date: desc_nulls_last }
limit: 1
where: { name: { _eq: "avg_gas_used" }, period: { _eq: "hour" } }
) {
total
end_date
}
}
Fetch daily average gas used for 30 days (timeseries)
query AvgGasUsedDaily {
ecosystem_metric(
order_by: { end_date: desc_nulls_last }
limit: 30
where: { name: { _eq: "avg_gas_used" }, period: { _eq: "day" } }
) {
total
end_date
}
}
Fetch current average gas for Ethereum transactions (hourly)
query AvgGasUsedEthereumTxHourly {
ecosystem_metric(
order_by: { end_date: desc_nulls_last }
limit: 1
where: { name: { _eq: "avg_gas_used_ethereum_tx" }, period: { _eq: "hour" } }
) {
total
end_date
}
}
Fetch monthly average gas used for contract calls (timeseries)
query AvgGasUsedContractCallMonthly {
ecosystem_metric(
order_by: { end_date: desc_nulls_last }
limit: 12
where: { name: { _eq: "avg_gas_used_contract_call" }, period: { _eq: "month" } }
) {
total
end_date
}
}
7-day percentage change (period comparison)
query AvgGasUsed7DayChange {
current: ecosystem_metric_aggregate(
where: { name: { _eq: "avg_gas_used" }, period: { _eq: "hour" } }
order_by: { start_date: desc_nulls_last }
limit: 168
) {
aggregate {
avg {
total
}
}
}
previous: ecosystem_metric_aggregate(
where: { name: { _eq: "avg_gas_used" }, period: { _eq: "hour" } }
order_by: { start_date: desc_nulls_last }
offset: 168
limit: 168
) {
aggregate {
avg {
total
}
}
}
}
Note: Percent Change = ((current - previous) / previous) * 100
Available Time Periods
The period field supports the following values:
hourdayweekmonthquarteryear
SQL Implementation
Below is a link to the Hedera Stats GitHub repository. The repo contains the SQL functions that calculate the Average Gas Used statistics outlined in this methodology.
SQL Functions:
ecosystem.avg_gas_used- Average gas across all gas-consuming transactionsecosystem.avg_gas_used_contract_call- Average gas for contract call transactions (type 7)ecosystem.avg_gas_used_ethereum_tx- Average gas for Ethereum transactions (type 50)ecosystem.avg_gas_used_contract_create- Average gas for contract creation transactions (type 8)
Dependencies
- Hedera mirror node