Gas

What is gas?

In our daily lives, we pay for almost everything we use, such as electricity and water. On our utility bills, these two are measured in kilowatt-hours and cubic meters. Similarly, in a decentralized system like Fantom, we also have charges for our activities, which are measured in gas.

Gas is a unit that measures the computational effort required to process a transaction. Think of it like how much fuel your car needs to drive a certain distance. A transaction’s gas used simply means how much gas was required for that transaction to be processed.

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. For each of these gas used, you must pay a price, 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, which is 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. Likewise, consider this comparison: if your car needs 50 liters of gasoline to get to 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 largely determined by the network’s congestion and tends to change constantly. On a quiet day, the gas price will be low, but on days with enormous amounts of activity, the gas price will be high. You can pay a higher gas price to incentivize validators to process your transaction faster than others who have set a lower price. Note that the gas used for your transaction remains the same, but you simply choose to pay more for each unit of gas.

As transactions can include complex operations at times, you won’t always know how much gas they will use. As such, the gas limit determines the maximum amount of gas you’re willing for your transaction to use to be processed. If you set a gas limit lower than what your transaction needs, it might be stuck waiting as no validator is willing to process it, much like you’ll be deserted halfway to your destination if you don’t fill your car with enough fuel.

Now most importantly, to whom is the transaction fee paid? Validators. This is the fee that 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