Gas

What is gas?

We pay for almost everything we use daily. For example, electricity and water consumption are measured in kilowatt-hours and cubic meters, respectively. Similarly, in a decentralized system like Fantom, we also have charges for our activities, measured in gas.

Gas, in the context of decentralized systems, is like the fuel your car needs to drive from A to B. Just as your car's fuel consumption depends on the distance and the car's efficiency, the amount of gas used in a transaction reflects the computational costs of processing the transaction.

For example, transferring FTM tokens takes 21,000 gas per transaction, swapping between two tokens might take 200,000 gas, and buying an NFT might take 600,000 gas. You pay a price for each gas unit, just like you must pay for every drop of fuel in your car.

The gas price measures how much you pay for every gas and is usually given in a unit called gwei, equivalent to a billionth of an FTM. For example, if a swap transaction takes 200,000 gas to process and the gas price is 30 gwei (0.00000003 FTM) per gas, you multiply these two numbers to get your transaction fee, which is the final price you pay for your transaction, as shown below. For example, if your car needs 50 liters of gasoline to reach its destination and the price of gasoline is 2 USD per liter, the overall cost is found by multiplying these two values.

Because there’s only a finite amount of space in each block for transactions, the gas price is determined mainly by the network’s congestion and tends to change constantly. On a slow day, the gas price will be low, but on days with lots of activity, the gas price will be high. You can pay a higher gas price to incentivize validators to process your transaction faster than other transactions that may have set a lower price. Note that the gas used for your transaction remains the same, but you pay more for each gas unit.

As transactions can involve complex operations, it's impossible to know how much gas they will use ahead of time. This is where the gas limit comes in. It's like setting a maximum budget for your car's fuel consumption. Suppose you set a gas limit lower than your transaction needs. In that case, it might be stuck waiting as no validator will process it or terminate the transaction because it runs out of gas, much like your car running out of fuel before reaching its destination.

Now, most importantly, to whom is the transaction fee paid? Validators. This fee incentivizes them to stake FTM to keep the Fantom network running by processing transactions and including them in blocks. The transaction fee also prevents spam, deters malicious actors by making attacks expensive, and ensures fair use of network resources.

Last updated

© 2024 Fantom Foundation