Convert gas to USD (Ethereum)

Understanding gas cost can be tricky because there are three components at play: the gas price, the price of ether, and the units of gas.

The “gas price” that you might see on a website like etherscan.io/gastracker, which fluctuates with network demand.

The price of Ether. Obviously, the more expensive ether is, the higher the gas cost.

Finally, “gas” which is a unit that tells you how expensive the transaction is. Transferring Ether from one account to another costs 21,000 gas. Interactions with smart contracts cost more.

Calculator

You can use this handy calculator if you just want to get a conversion done.

Gas Price

The “gas price” is usually priced in units of Gwei. The values fluctuate between 15 during periods of low use to over 100 gwei during periods of high use. What exactly is a “gwei” in this context?

Ethereum, as a cryptocurrency, can be subdivided into decimal places of 10^-18. Each of these tiny units is called one “wei.” One billion wei, or one giga-wei, is one billionth of an Ether, or 1 billion wei. (Multiplying 10^-18 by one billion is 10^-9, or one billionth).

“Gwei” is a handy unit of measure because gas prices happen to fluctuate around one billionth of an ether per unit of gas.

The gas price is how much units of ether (not dollars) you need to pay per unit of gas. The dollar cost comes from converting ether to dollars.

Gas

Not to be confused with “gas price” which fluctuates, the gas cost is fixed per transaction. The more complex the transaction, the higher the gas cost. Ethereum transfers, for example, always cost 21,000 gas. Transferring ERC20 tokens usually costs approximately 50,000 gas.

Gas can be conceptualized as a “unit of computation” or very roughly, one clock cycle on a hypothetical CPU.

Conversion

(21,000 gas) $\times$ (price of gas in gwei) $\times$ (price of ether in dollars) / (1 billion to normalize the gwei)

At the time of writing, Ether is about $1,600, the price of gas in gwei is 22 according to etherscan, and an eth transfer requires 21,000 gas. Multiply that together and the gas cost of transferring Ether in dollars is 74 cents.

How the units cancel each other out

21,000 gas x (unit of ether / gas) $\times$ (dollars / unit of ether).

The “gas” terms cancel out, and the “unit of ether” cancel out, so our final transaction is priced in dollars.

Why gas prices fluctuate

Ethereum limits each block to only use 30 million gas. Divide that by 21,000, and that means up to 1,428 Eth transfers can be done in one block. If more than 1,428 people want to make a transfer, they’ll have to wait or pay a higher gas price. Remember, they can’t change the 21,000 cost of a transfer, or the price of Ether (directly). The gas price is discretionary, transactors can pay as high a price as they chose, but for their transaction to be included, they must pay higher than the other transactors.

Because block space is limited, there is a supply and demand phenomenon at play. If more people want to send transactions than Ethereum has space for, then the most motivated buyer must outbid the other transactors.

Gas Price Seasonality

These usage patterns are highly seasonal. Much of the trading happens in America daytime, so during their daytime hours, prices are usually higher. This heatmap from ethereumgasprice.org is very handy.

Here is a snapshot taking during the writing of this article. The local timezone is in Asia time, so during Asia’s night time (United States day time), the gas price is higher. Also note that the weekend sees less usage.

Ethereum gas price heatmap

Gas Guzzlers

Scroll down on the etherscan gas page, and you’ll see the smart contracts that cause the most gas consumption. The pattern of gas consumption follows the Pareto principle (80 20 rule), 80% of the gas consumption comes from 20% of the ecosystem.

At the time of writing, transaction fees associated with Uniswap consumes 10% of the network.

Ethereum burns most of the transaction fee (the miner receives a small portion), so this indicates that Uniswap alone has resulted in over 400 Ether being deleted over the past 24 hours.

Learn more

Our Solidity Bootcamp teaches gas optimization and pricing very thoroughly.

Originally Published March 7, 2023

Storage Slots in Solidity: Storage Allocation and Low-level assembly storage operations

Storage Slots in Solidity: Storage Allocation and Low-level assembly storage operations This article examines the storage architecture of the Ethereum Smart Contracts. It explains how variables are kept in the EVM storage and how to read and write to storage slots using low-level assembly (Yul). This information is a prerequisite to understanding how proxies in […]

The second preimage attack for Merkle Trees in Solidity

The second preimage attack for Merkle Trees in Solidity The second preimage attack in Merkle trees can happen when an intermediate node in a merkle tree is presented as a leaf. The name of this attack is quite misleading because it implies hashes have a second preimage. Modern hash functions do not have multiple (computable) […]

Ethereum precompiled contracts

Ethereum precompiled contracts Ethereum precompiles behave like smart contracts built into the Ethereum protocol. The nine precompiles live in addresses 0x01 to 0x09. The utility of precompiles falls into four categories – Elliptic curve digital signature recovery – Hash methods to interact with bitcoin and zcash – Memory copying – Methods to enable elliptic curve […]

EIP-2930 – Ethereum access list

EIP-2930 – Ethereum access list Introduction An Ethereum access list transaction enables saving gas on cross-contract calls by declaring in advance which contract and storage slots will be accessed. Up to 100 gas can be saved per accessed storage slot. The motivation for introducing this EIP was to mitigate breaking changes in EIP 2929, which […]