Gas

Think of gas in Ethereum as fuel for a car. Just as a car needs gasoline to run, the Ethereum network needs gas to operate. When you send an Ethereum transaction, you have to pay for the computational resources it uses, and this payment is the gas fee.

Gas refers to the unit that measures the amount of computational effort required to execute specific operations on the Ethereum network.

The gas fee is determined by two things: the amount of gas needed for the operation and the cost per unit of gas. It's like paying for the distance your car travels (gas used) and the price of each liter of gasoline (cost per unit of gas). Importantly, you pay the gas fee whether your Ethereum transaction succeeds or fails.

Why do gas fees exist?

The gas system helps prevent spam and ensures that Ethereum doesn't get stuck in never-ending computations.

Preventing Spam: In a digital system like Ethereum, spam can occur if there is no cost associated with performing actions. Imagine someone sending a massive number of meaningless transactions just to overload the network. The gas system requires users to pay for the computational resources they use, acting as a deterrent against malicious transactions.

Avoiding Infinite Computations: Ethereum transactions involve executing code, and sometimes there's a risk of code getting stuck in an infinite loop (a never-ending series of computations). Without proper controls, this could potentially freeze the entire network. The gas system imposes limits on how much computation can be done in a single transaction by requiring users to pay for each computational step. If a transaction consumes too much gas without completing, it will simply be halted, preventing infinite loops and ensuring the overall stability and responsiveness of the Ethereum network.

Gas fees have to be paid in Ethereum's native currency, ether (ETH). Gas prices are commonly expressed in gwei, a unit of ETH. One gwei is equivalent to one-billionth of an ETH (0.000000001 ETH or 10-9 ETH). For example, instead of saying that your gas costs 0.000000001 ether, you can say your gas costs 1 gwei.

https://ethereum.org/en/developers/docs/gas/

Last updated