Touring Sonic — What is Gas?
The Sonic testnet phase is currently in full swing, with many people engaging with the open testnet to experience its incredible performance. As part of that, many technical terms are being thrown around for evaluating the network and its transactions. Our Touring Sonic series will shed light on some of these key terms.
In this article, we’ll explain the meaning of gas used, gas price, transaction fee, and gas limit.
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.
Feel free to use your newfound knowledge by exploring the transactions on the Sonic open testnet, or submit your own transactions to the network and check your gas settings to learn how they are implemented in practice.
Within the Sonic closed testnet, the average gas used by transactions is around 200,000 gas. The transactions are distributed roughly as shown below.
- 10% constitutes native token transfers with 21,000 gas per transaction.
- 64% constitutes ERC20 token contracts executing the transfer or mint functions with 40,000 gas per transaction.
- 25% constitutes Uniswap chained trades of 10 consecutive swaps of ERC20 tokens via Uniswap pairs with about 600,000 gas per transaction.
- 1% constitutes chained swap trades of 32 ERC20 tokens via Uniswap pairs connected in a loop with roughly 2 million gas per transaction.
Frequently asked questions
The launch of Sonic comprises three main components that scale Fantom to new heights:
● A new virtual machine, the Fantom Virtual Machine (FVM), which increases our transaction throughput significantly while maintaining ultra-short finality.
● A new database storage, Carmen, which reduces storage requirements by up to 90%, providing greater cost efficiency for validators and accelerating the Foundation’s ability to deploy archive nodes from weeks to approximately 36 hours.
● An optimized Lachesis consensus mechanism, which brings a vastly improved transaction pool.
Fantom Sonic is in its testnet stage at the moment and will roll out as a mainnet to replace Fantom Opera in spring 2024. Currently, Sonic offers two different testnets: the closed testnet aims to showcase the maximum theoretical limits of Sonic, whereas the open testnet is interactive, allowing any user to experience Sonic directly.
Most importantly, this new virtual machine allows Fantom validators to execute smart contracts more efficiently.
The closed testnet is viewable only and aims to showcase the maximum theoretical limits of Sonic, whereas the open testnet is interactive, allowing any user to experience Sonic directly.
However, there may be even more significant performance gains with further testing that may require a hard fork in the future, but the current plan is not to hard fork Fantom Opera.