Back to Listicles
LISTICLE10 min read2025-06-23

How to Calculate Blockchain Gas Costs — Complete Cost Estimation Guide

Understanding gas cost calculation helps you design cost-effective smart contracts and accurately estimate user transaction costs.

ClickMasters Team
Curated recommendations
Expert selected
Expert Recommendation

Need Help Optimizing Gas Costs?

Get expert guidance on designing cost-effective smart contracts.

Curated List

Quick Take

Gas cost calculation: Transaction cost (ETH) = Gas used × Gas price. Gas price (post EIP-1559) = Base fee + Priority tip. Example: Simple ETH transfer: 21,000 gas × 16 gwei = 0.000336 ETH (~$0.67). ERC-20 transfer: ~65,000 gas (~$2.08). DeFi swap: ~150,000–200,000 gas (~$4.80–$6.40). NFT mint: ~70,000–100,000 gas (~$2.24–$3.20). L2 comparison: Ethereum L1 ($0.50–$10 transfer), Arbitrum ($0.01–$0.15), Base ($0.001–$0.05), Polygon PoS ($0.001–$0.01), Solana ($0.0003). Foundry's `forge test --gas-report` provides detailed gas usage metrics.

Ethereum Gas Fundamentals

Transaction cost (ETH) = Gas used × Gas price

Gas price (post EIP-1559) = Base fee + Priority tip

Base fee: Set by the network, burned (fluctuates with demand)

Priority tip: Set by user, goes to validator (typically 0.1–2 gwei)

Example (during moderate congestion):

1

Base fee: 15 gwei

2

Priority tip: 1 gwei

3

Total gas price: 16 gwei = 16 × 10^-9 ETH

Simple ETH transfer: 21,000 gas

Cost: 21,000 × 16 × 10^-9 ETH = 0.000336 ETH ≈ $0.67 at $2000/ETH

ERC-20 transfer: ~65,000 gas

Cost: 65,000 × 16 × 10^-9 ETH ≈ $2.08

Complex DeFi swap (Uniswap V3): ~150,000–200,000 gas

Cost: ~$4.80–$6.40

NFT mint (ERC-721): ~70,000–100,000 gas

Cost: ~$2.24–$3.20

Layer 2 Gas Comparison

ChainSimple TransferERC-20 TransferDeFi Swap
Ethereum L1$0.50–$10$1–$20$3–$60
Arbitrum One$0.01–$0.15$0.02–$0.30$0.05–$0.50
Optimism$0.01–$0.10$0.02–$0.25$0.04–$0.40
Base$0.001–$0.05$0.002–$0.10$0.01–$0.20
Polygon PoS$0.001–$0.01$0.002–$0.02$0.005–$0.05
Solana$0.0003$0.0003$0.0003

Gas Cost Estimation in Foundry

Example
# Estimate gas for a specific function call
forge test --match-test test_Deposit -vvvv 2>&1 | grep "gas"

# Generate gas report for entire test suite
forge test --gas-report

# Example gas report output:
# | Function    | min   | avg   | median | max   |
# | deposit     | 45782 | 52341 | 50123  | 89234 |
# | withdraw    | 38234 | 41234 | 40123  | 75234 |

# Profile specific transactions
forge snapshot --match-test test_LargeDeposit

Estimating Annual Infrastructure Cost for a dApp

Frequently Asked Questions

Common questions about this list

Clear answers to help you understand how these options were selected and how to choose the best fit.

1

Answers

Why is gas on L2 cheaper than Ethereum L1?

L2s batch hundreds/thousands of transactions and post compressed batch data to Ethereum L1 as a single transaction. The L1 cost is amortized across all transactions in the batch. Post-EIP-4844 (blob transactions): blob data is even cheaper than calldata, reducing L2 costs by 10–100x further.

Expert Recommendation

Need Help Optimizing Gas Costs?

Get expert guidance on designing cost-effective smart contracts.