Gas
Gas is the unit used to measure the computational effort required to execute operations on the Ethereum network. Since every operation—such as writing to storage, performing math, or sending tokens—consumes computing resources, gas ensures that network participants are compensated for their work. Users must pay for this gas in Ether, which prevents spam and ensures that infinite loops or resource-intensive tasks cannot clog the network, as the execution will fail once the provided gas is exhausted.
Explain Like I'm 12
Think of gas like fuel for a car. Your car needs fuel to travel, and the farther or faster you drive, the more fuel you use. On the blockchain, 'driving' is like running code. To run your smart contract, you need to pay for the 'fuel' (gas) required to keep the computer performing your task.
Why It Matters
Gas is the primary mechanism for network security and economic sustainability. It prevents malicious users from flooding the network with endless, free calculations that would otherwise crash the nodes.
How It Works
Each operation in the EVM has a predefined gas cost defined in the Ethereum Yellow Paper. When a transaction is sent, the user defines a gas fee. The EVM deducts gas for each step executed; if the transaction completes, the remaining gas is refunded. If the gas runs out, the state changes are reverted.
Real-World Example
Sending a simple ETH transfer uses 21,000 gas, whereas interacting with a complex NFT minting contract may cost hundreds of thousands of gas depending on the operations.
Advantages
- Prevents network spam
- Compensates node operators
- Ensures computation is finite
Limitations
- Fluctuating prices affect user experience
- High costs discourage small transactions
- Complexity of optimization for developers
Common Misconceptions
- People often think gas is the same as the network fee, but the fee is a product of gas used and gas price.
- Some believe gas prices are fixed by the blockchain, but they are determined by network demand.
Knowledge Explorer
Explore This Concept in the Knowledge Graph
See how Gas connects to other concepts, books, research, and developer resources.
Related Terms
EVM
The Ethereum Virtual Machine (EVM) is a decentralized, Turing-complete computation engine that executes smart contracts on the Ethereum network. It functions as a global state machine, where the state is updated based on code execution on the blockchain. Because the EVM is implemented by every node in the network, it ensures that smart contracts run exactly as intended across all devices, regardless of local hardware differences. This allows for complex, programmable logic to be embedded into the blockchain.
Ethereum
Ethereum is an open-source, decentralized blockchain network that enables the creation and execution of smart contracts and decentralized applications (dApps). Launched in 2015, it introduced the concept of a programmable blockchain, moving beyond simple peer-to-peer value transfers. By utilizing the Ethereum Virtual Machine (EVM), it allows developers to build self-executing code that operates without intermediaries, censorship, or downtime, creating a foundation for a new internet economy, often referred to as Web3.
Gwei
Gwei is a denomination of Ether (ETH), the native currency of the Ethereum network. Since standard Ether is too large for most transaction fee calculations, the network uses Gwei (short for giga-wei) to measure gas prices. One Gwei is equal to one-billionth of an Ether (10^-9 ETH). It serves as the standard unit for expressing the cost of computational effort required to process transactions and execute smart contracts, allowing for precise fee management.
Node
A node is any computer or device that connects to a blockchain network and participates by running the protocol's software. Nodes play various roles, including validating transactions, maintaining a copy of the blockchain history, and propagating new data to other peers. Different types of nodes exist, such as full nodes (which store the entire blockchain history and enforce all rules) and light nodes (which store only headers for efficiency). Nodes are the active participants that uphold the network's integrity and decentralization.
Smart Contract
A smart contract is a self-executing program stored on a blockchain that automatically runs when predetermined conditions are met. These contracts eliminate the need for intermediaries by encoding terms directly into lines of code, ensuring that the agreement is enforced exactly as written without human interference. Because they reside on an immutable ledger, the execution results are verifiable, transparent, and impossible to tamper with once deployed.
Smart Contract
A self-executing program stored on a blockchain that automatically enforces and executes the terms of an agreement when predetermined conditions are met. Smart contracts are deterministic, immutable once deployed, and form the backbone of decentralized applications.
Transaction
A transaction is an cryptographically signed instruction that alters the state of a blockchain ledger. When a user sends assets, executes a smart contract, or updates data, the transaction is broadcast to the network, verified by nodes, and permanently recorded in a block. Transactions serve as the fundamental unit of activity on any blockchain, ensuring that changes to the distributed database are legitimate, verified, and irreversible through consensus mechanisms.