How Does Ethereum Gas Work in Accounts and Wallets?

Researched with a video published on YouTube by 99Bitcoins. Tech Feed Watch is not affiliated with the creator, and all rights to the video remain theirs.

Ethereum operates on a distinct account and transaction model, differing significantly from simple value transfer systems like Bitcoin. Understanding Externally Owned Accounts (EOAs), Contract Accounts, and the nuanced role of Gas is fundamental for effective interaction with the network. Wallets serve as critical interfaces, managing private keys and facilitating not just Ether transfers but also complex smart contract executions. The inherent complexity of Ethereum's design underpins its capabilities as a decentralized computing platform.

13 min video · 7 min read. Spend 7 min here to decide whether the other 6 are worth it.

Ethereum operates as a decentralized computing platform, capable of executing complex programs called smart contracts, rather than solely facilitating currency transfers. Interacting with this network relies on distinct account types and a unique transaction fee mechanism known as Gas. Gas is a unit of account that measures the computational effort required to perform operations on the Ethereum network. It ensures that every action, from a simple Ether transfer to a complex smart contract execution, incurs a cost, preventing network abuse and incentivizing validators.

Understanding Ethereum’s Account System

Unlike simpler blockchain systems that primarily handle value transfers, Ethereum employs two fundamental account types to support its computing abilities. The most basic is the Externally Owned Account (EOA). Similar to how a Bitcoin wallet works, an EOA is controlled by a private key, which acts as a secret password giving its owner control over the account’s funds. Each EOA has a unique Ethereum address, allowing people to send Ether, Ethereum’s native currency, to it. Beyond just sending and receiving Ether, EOAs can also create new smart contracts and trigger existing ones. People can open as many EOAs as they wish.

The second type is the Contract Account. These accounts are unique because they have code associated with them. Every smart contract deployed onto the Ethereum network is assigned its own Contract Account, complete with a unique Ethereum address. However, unlike EOAs, Contract Accounts do not have a private key. Instead, their operations are controlled by the code embedded within the contract itself, which includes predefined triggers and conditions. Once a contract is launched, its code cannot be changed, making careful drafting essential. Contract Accounts can receive Ether, and when triggered by their code, they can send Ether or even create additional Contract Accounts. EOAs interact with other EOAs and with Contract Accounts by sending messages, which are “wrapped” inside transactions.

The Multifaceted Role of Ethereum Transactions

On Ethereum, transactions serve a broader purpose than just moving value from one address to another, as is often the case with systems like Bitcoin. They are the primary means by which accounts communicate and execute operations on the network.

There are three main uses for Ethereum transactions:

  • Transfer of Value: This is the simplest form, involving sending Ether directly between two accounts.
  • Creation of Smart Contracts: To deploy a new smart contract onto the network, a transaction is sent that includes the contract’s code. This creates a new Contract Account.
  • Triggering Smart Contracts: Transactions can activate the functions of an existing smart contract. For example, when someone sends Ether to an Initial Coin Offering (ICO) contract address, they are typically triggering a function within that contract that sends them tokens in return.

Some Ethereum wallets are designed only for transferring Ether between accounts. More advanced “Smart contract wallets,” however, allow users to deploy new contracts or interact with existing ones.

Gas: Fueling the Ethereum Supercomputer

Gas is fundamental to how the Ethereum network operates. It is a unit of measurement for the computational work required to execute any operation. Think of it like the fuel for a car or hours of labor for a task. Each line of code or specific action on the network consumes a certain amount of gas. If an operation runs out of gas mid-execution, it halts. This system incentivizes smart contract programmers to write efficient, optimized code, as gas costs money.

The gas paid for transactions goes to the miners (or validators in newer Ethereum versions) who invest computing power to process and include transactions in new blocks on the blockchain. Gas is not a cryptocurrency that users can own; it is purely a unit of account. While gas is measured in these units, it is in the end paid for in Ether.

A common question is why a separate unit like Gas is needed instead of simply pricing operations directly in Ether. The reason is Ether’s fluctuating market price. If contract execution costs were fixed in Ether, the real-world dollar cost would constantly change. Gas provides a stable measure of computational cost. Just as painting a house takes a consistent number of hours, running the same smart contract always requires the same amount of gas, regardless of Ether’s price.

The amount of gas required for specific actions is predefined. For instance, sending Ether from one address to another requires 21,000 gas units. The actual price of one gas unit, however, changes dynamically based on network congestion. When the network is busy, the gas price rises, similar to how an hour of labor costs more when demand for workers is high. The “standard” gas price is often around 20 Giga Wei, where one Giga Wei equals one billion Wei, and one quintillion Wei equals one Ether. Users can choose to pay a higher gas price to incentivize miners to prioritize their transaction, leading to faster inclusion in a block.

Managing Gas: Costs, Risks, and Optimization

When initiating an Ethereum transaction, users must specify a “gas limit,” which is the maximum amount of gas they are willing to spend on that operation. This limit protects users from depleting their funds if a contract contains an error that causes it to run endlessly or inefficiently. The full amount for the gas limit is paid upfront.

If a transaction uses less gas than the specified gas limit, the unused gas is refunded to the sender. However, if an operation runs out of gas before completing, it will halt, and no Ether will be returned. This can occur if the gas limit was set too low for a complex contract function or if the code was inefficient. And, if a transaction does not include enough gas units to cover its minimum execution cost, miners will not pick it up.

Another consideration is the gas price. If a user sets a very low gas price, even with a sufficient gas limit, their transaction may take a long time to be processed. Miners prioritize transactions that offer higher gas prices, meaning lower-paying transactions might wait in a queue until network congestion subsides. Therefore, the total transaction fee is calculated as the amount of gas used multiplied by the gas price paid per unit. A higher gas price encourages miners to include a transaction faster.

Ethereum Wallets: Your Interface to the Network

Ethereum wallets are essential tools, whether they are software applications or hardware devices, that enable users to interact with the Ethereum network. At their core, wallets securely hold your private key, which is the secret credential that grants control over your Ether and other digital assets. They also provide your public Ethereum address, which others use to send you funds.

Wallets vary in their abilities. Some are simple, allowing only the transfer of Ether between accounts. Others, known as “Smart contract wallets,” offer more advanced features, such as the ability to deploy new smart contracts or trigger functions within existing ones.

There are different ways to run an Ethereum client, which is another term for a wallet or node:

  • Full Clients (Nodes): These are computers that download and store the entire history of the Ethereum blockchain from its inception. Running a full node, while resource-intensive in terms of memory and computer usage, offers the highest level of security and decentralization. It allows users to verify transactions independently without relying on third parties. Full nodes are integral to the network’s operation, executing contract code in a decentralized manner. Popular full clients include Geth (Go Ethereum), developed by the Ethereum Foundation, and Parity, developed by a private company. At one point, there were 9713 Geth nodes and 4069 Parity nodes running. All full nodes inherently function as smart contract wallets.
  • Light Clients (Nodes): For users who do not wish to run a full node, light clients offer a less resource-intensive alternative. These programs rely on third-party full nodes to retrieve necessary information, rather than storing the entire blockchain history themselves. This makes them suitable for devices with limited storage, such as mobile phones. Light clients are often preferred by everyday users who primarily want to send and receive Ether due to their ease of installation and operation.
  • Hardware Wallets: For enhanced security, hardware wallets are physical devices designed to store private keys offline. They are considered the most secure way to store Ether and ERC-20 tokens. While they cost money, they protect private keys from online threats. By design, most hardware wallets are not smart contract wallets; they typically support sending and receiving Ether and tokens but not deploying or directly triggering complex smart contracts.

Ethereum’s design, with its distinct account types, versatile transactions, and gas mechanism, underpins its power as a decentralized computing platform. This complexity enables a wide range of applications beyond simple currency transfers, from decentralized finance (DeFi) to non-fungible tokens (NFTs).

Frequently Asked Questions

What is Gas in Ethereum?

Gas is a unit of measurement for the computational effort required to execute operations on the Ethereum network. It acts as a fee mechanism to incentivize validators for processing transactions and to prevent network abuse by requiring a cost for every action.

How is an Ethereum transaction fee calculated?

An Ethereum transaction fee is calculated by multiplying the amount of Gas used by the operation by the Gas Price. The Gas Price is the cost per unit of Gas, which fluctuates based on network congestion, and is paid in Ether (typically in Giga Wei).

What is the difference between an Externally Owned Account (EOA) and a Contract Account?

An EOA is controlled by a private key held by a user, allowing them to send/receive Ether and initiate smart contract interactions. A Contract Account, on the other hand, is controlled by its embedded code, has no private key, and executes predefined functions when triggered by transactions.

What happens if an Ethereum transaction runs out of gas?

If an Ethereum transaction runs out of gas before completing its operation, it will halt, and the transaction will fail. In this scenario, no Ether will be returned to the sender, even though the operation did not finish.

Jacob S. Olsen

Jacob S. Olsen

Runs Tech Feed Watch, from Denmark

How this article was made: every article starts from two things — a question people search for on Google, and a video from an independent creator on that subject. A language model writes the article to answer the question, using the video's transcript as its research material. It publishes automatically — I do not read every article before it goes live. The creator is credited on this page.

What is mine is the machinery and the rules it follows: which subjects, which sources, what gets rejected, and what this site is allowed to claim. More on that here — and if something is wrong, tell me.