What is gas in Ethereum, gas limit and gas station + other currencies


A reward was awarded for the post

This material was written by a site visitor and was compensated for.

Just started using the Ethereum network? Is this the first time you have come across such a concept as “gas”? In this article, we will try to consistently understand the transaction features of the Ethereum network. Let's look at concepts such as Gas, Gas limit, Gas price, as well as Gwei

Gas to Ethereum

If you have in any way worked with smart contracts, transferred ETH, or participated in an ICO, then you have encountered gas. This mechanic, expressed in the gas limit and gas price, is key to conducting transactions in the Ethereum ecosystem.

To understand the details, you need to remember the basic concept of the Ethereum project.

Ethereum is a giant network that consists of connected computers with an installed client. This interconnected network is called the Ethereum Virtual Network (EVN), like a global supercomputer where all transactions are updated and recorded on every computer.

Ether (ETH) is the internal currency of the Ethereum blockchain and is used as “fuel” for the network: for operations, value transfer, and reward systems.

New to the Ethereum blockchain was the ability to execute smart contracts (relative to Bitcoin). These are contracts that are pre-programmed with a set of necessary rules and regulations and are self-executed without the need for an intermediary.


how smart contracts work

Why do transactions take so long?

Since all users are competing with each other for block space, if you set your gas fee too low, miners will choose not to include your transaction in a block in the near future. So your transaction is taking so long because you haven't set your gas fee high enough for your transaction to be included in the block in the near future. You will have to wait for the gas fees that other users are willing to pay to decrease in order for your gas fees to be attractive to miners.

Disclaimer: This article is intended for general guidance and informational purposes only for those new to cryptocurrencies and DeFi. The contents of this article should not be construed as legal, business, investment or tax advice. You should consult your own advisors for all legal, business, investment and tax implications and advice. ConsenSys is not responsible for lost funds. Please use common sense and do your due diligence before interacting with smart contracts.

Spread the love

Why do we need gas?

ETH is publicly traded on exchanges and its market price can change quickly. The creation of GAS units is to decouple the cost of computational work on the Ethereum network from the volatile market price of Ethereum, since the cost of computation does not change as quickly.

Example:

When you create a smart contract, you expect fixed fees in ether. For example, when ETH cost $10, and you needed to pay 0.5 ETH for the work, the price in dollars suited you - only $5.

But ether has grown, now for 0.5 ETH you will have to pay 250 dollars, for example. This makes it difficult to use the system to develop and run applications. Therefore, a gas system was created.

What is Gas?

Gas in Ethereum is a unit of measurement of computational work to carry out transactions or smart contracts on the Ethereum network. This is not a coin, not some part of a token, it is a dynamic indicator through which an invoice will be issued in ETH.

This system is similar to using kilowatts to measure electricity in a home. The amount of electricity consumed is not immediately measured in rubles; instead, the bill is billed per kW/h.

It is important to understand that different types of transactions require different amounts of gas. As with electricity or gasoline: a powerful device or engine will spend more compared to a weak one.

For example, a simple transaction to send ETH from address to address costs 21,000 gas. Execution of smart contracts is carried out by the miner, who spends his time, electricity and power to execute the codes and complete the transaction. For a smart contract, gas will be different.

ETH Transaction Log

To track various kinds of transfers and messages, the Ethereum network keeps logs. They are generated every time a transaction is executed.

The logs contain the following information:

  • Log registrar account address;
  • Topics representing the various actions produced as a result of this transaction;
  • Data that is associated with these tasks.

Gas Limit

The gas limit is the maximum amount of gas you are willing to spend on a specific transaction. High gas levels mean that a lot of computational work needs to be done to execute a smart contract.

A standard ETH transfer requires a gas limit of 21,000 gas. This is indicated in the additional options in the wallet during the transfer. You need to indicate the limit with a margin: unspent units will still come back.

The image above notes that the gas limit is set at 42000. The transaction required 21080 GAS units, the current price in ETH and Gwei for one gas and the total cost of the transaction.

The more complex the commands you want to execute, the more gas you have to pay. You can see this in action when you participate in an ICO for ETH or when you want to list coins on an exchange - the transfer fee is much higher than the default 21,000 gas. This is because ICO smart contracts have much more complex codes and require much more computation than simply transferring ETH. Usually about 200-300 thousand Gas.

The gas limit - the limit - acts as a safety mechanism to protect you from completely wasting your funds due to any mistakes.

An already classic example of a gas limit is a car tank designed for a certain amount of fuel.

Gas Station - current price for gas

Recommended gas prices (based on current network conditions):

  • for a low priority transaction (up to 30 minutes) - 1 Gwei
  • standard time (up to 5 minutes) - 3 Gwei
  • high priority, transaction in the next block (less than 2 minutes) – 6 Gwei

The user sets the price independently, but often everyone trusts the default settings in the wallet. Sometimes the price can be reduced if the transaction does not need to be carried out very urgently. The safest lowest price for June 2022 is listed above.

To further reduce the transaction fee in Ethereum, you can set the price for 1 gas in the region of 1-2 wei (the smallest part of Ether). As long as the mempool is not overloaded and the blocks are not filled to capacity (maximum capacity is 6,700,000 gas), such a transaction can also be withdrawn. But it can be risky. In addition, in MyEtherWallet and the official client you cannot set the price below 1Gwei through the slider. In MEW, the method works with “Offline transfer”.

EthGasStation is designed to increase the transparency of gas prices; there you can see all the current data on gas and transactions on the Ethereum network. This site helps you determine the current market price per unit of gas and avoid overpaying.

Located at ethgasstation.info

Where do your gas fees go?

You may ask, “Why will my transaction be confirmed if I charge a higher gas fee?” Great question!

When you send a transaction on Ethereum, you are competing with other people who also want to send a transaction. While you can send your mom some ether, someone in India can trade on Uniswap. Each person is trying to complete their transaction at the same time. But only a certain number of transactions can be included in an Ethereum block, and only new blocks are created every approximately 13 seconds. In fact, each block contains only 12.5 million units of gas. This means that everyone is competing with each other to include their transaction in the next block. When demand is high and supply is limited, since only a certain number of transactions can be included in a block, the price must increase.

But when you send transactions, where are they before the miners approve them? These transactions are sent to a memory pool, short for memory pool. The mempool is where all transactions that have been sent but not yet verified are located. In short, a mempool is a queue waiting for verification. Miners, who check transactions before execution to ensure they are not malicious, select transactions to be included in the next block from the mempool.

“So why do miners choose my transaction from the mempool before anyone else?” Because of course I'll pay them more!

Miners choose which transactions should be included in the next block based on how high the gas fee is set by users before sending the transaction. The higher the gas fee, the higher the likelihood that the miner will want to include your transaction in the next block. In this situation, there is competition because you are competing with everyone by charging gas fees for that period of time for block space.

What to do if there is not enough gas for a transaction?

Transactions will be processed by miners until you run out of gas. The blockchain will record the transaction as “Failed” and the ETH will remain in the wallet because there is not enough gas to complete the transfer.

The gas used for a failed transaction will remain with the miners and you will NOT get it back. This is due to the fact that resources were wasted on performing the translation.

To correct a transaction with a low gas amount, you need to wait for it to fail and re-enter it, specifying the correct limit. Unfortunately, it is no longer possible to increase the limit during the process.

Again:

  • you need to indicate the gas limit with a margin,
  • different operations will use gas differently,
  • miners will not process the transfer once the limit is reached,
  • the gas remaining after the transaction is returned.

Generating a transaction receipt

The logs in the header are derived from the log data contained in the receipt of completed transfers. When purchasing in stores, you receive a receipt. Same with Ethereum: it generates receipts for transactions. The receipt contains the following information:

  • block number;
  • block hash;
  • transaction hash;
  • the amount of gas used to perform the transfer;
  • the total volume of gas used in this block after the transfer was completed;
  • logs generated during the transaction and other information.

Gas for smart contract developers

Running smart contracts on the network costs more because they perform different actions. Each smart contract is developed individually and adapted to the needs of the project. For example, for an elite project you can afford a gas price of $5, but for some messenger - not.

There are two main costs associated with sending and executing an Ethereum transaction:

  • Execution cost,
  • Transaction cost.

The cost of execution is primarily related to the storage of global variables and the processing power used for calculations.

Here are the prices for different operations:

  • Add or subtract two integers 3 gas
  • Multiply or divide two integers 5 gas
  • Compare two integers 3 gas
  • Create a new contract 32000 gas
  • Storing a 256-bit word 20000 gas
  • Save 1 MB (31250 256-bit words) 625000000 gas
  • Send 1 transaction 21000 gas
  • Include 1 byte (not zero) in transaction data 68 gas
  • Include 1 MB in transaction data 68000 gas
  • Contract deployment (first time) ~ 32,000 gas
  • Transaction input overhead (total) ~4 for 0-byte and 64 for non-0 byte inputs
  • Transaction cost under the contract ~ 32,000 gas

Also for individual operations:


A well-written contract will likely move the maximum amount of computation off-chain.

The overall size of the smart contract will play a role in the fee. If you can split the contract into smaller individual parts, it will reduce gas costs when dealing with them.

The most expensive operation in terms of gas is storage. Storing large amounts of data on the blockchain is usually not used: most often only the hash is stored. And shorten the code:

string STATUS = 'unknown status'; —> uint STATUS = 0; //T

You also need to remove as much duplication within structures as possible.

Developers need to be aware of these costs and design dApps with them in mind.

All about gas in Ethereum and other cryptocurrencies

Crypto Fox

Jun 29, 2022 · 7 min read

In this article we talk about the concept of a gas limit, the concept of gas itself and its price, which is a central feature of the Ethereum blockchain and the entire ecosystem. We also answer the question of whether GAS is a separate currency. In addition, we talk about Gas in Neo and ETH Classic.

If you have in any way worked with smart contracts, transferred ETH, or participated in an ICO, then you have encountered gas. This mechanic, expressed in the gas limit and gas price, is key to conducting transactions in the Ethereum ecosystem.

To understand the details, you need to remember the basic concept of the Ethereum project.

Ethereum is a giant network that consists of connected computers with an installed client. This interconnected network is called the Ethereum Virtual Network (EVN), like a global supercomputer where all transactions are updated and recorded on every computer.

Ether (ETH) is the internal currency of the Ethereum blockchain and is used as “fuel” for the network: for operations, value transfer, and reward systems.

New to the Ethereum blockchain was the ability to execute smart contracts (relative to Bitcoin). These are contracts that are pre-programmed with a set of necessary rules and regulations and are self-executed without the need for an intermediary.

ETH is publicly traded on exchanges and its market price can change quickly. The creation of GAS units is to decouple the cost of computational work on the Ethereum network from the volatile market price of Ethereum, since the cost of computation does not change as quickly.

Example:

When you create a smart contract, you expect fixed fees in ether. For example, when ETH cost $10, and you needed to pay 0.5 ETH for the work, the price in dollars suited you - only $5.

But ether has grown, now for 0.5 ETH you will have to pay 250 dollars, for example. This makes it difficult to use the system to develop and run applications. Therefore, a gas system was created.

Gas in Ethereum is a unit of measurement of computational work to carry out transactions or smart contracts on the Ethereum network. This is not a coin, not some part of a token, it is a dynamic indicator through which an invoice will be issued in ETH.

This system is similar to using kilowatts to measure electricity in a home. The amount of electricity consumed is not immediately measured in rubles; instead, the bill is billed per kW/h.

It is important to understand that different types of transactions require different amounts of gas. As with electricity or gasoline: a powerful device or engine will spend more compared to a weak one.

For example, a simple transaction to send ETH from address to address costs 21,000 gas. Execution of smart contracts is carried out by the miner, who spends his time, electricity and power to execute the codes and complete the transaction. For a smart contract, gas will be different.

The gas limit is the maximum amount of gas you are willing to spend on a specific transaction. High gas levels mean that a lot of computational work needs to be done to execute a smart contract.

A standard ETH transfer requires a gas limit of 21,000 gas. This is indicated in the additional options in the wallet during the transfer. You need to indicate the limit with a margin: unspent units will still come back.

The image above notes that the gas limit is set at 42000. The transaction required 21080 GAS units, the current price in ETH and Gwei for one gas and the total cost of the transaction.

The more complex the commands you want to execute, the more gas you have to pay. You can see this in action when you participate in an ICO for ETH or when you want to list coins on an exchange - the transfer fee is much higher than the default 21,000 gas. This is because ICO smart contracts have much more complex codes and require much more computation than simply transferring ETH. Usually about 200–300 thousand Gas.

The gas limit - the limit - acts as a safety mechanism to protect you from completely wasting your funds due to any mistakes.

An already classic example of a gas limit is a car tank designed for a certain amount of fuel.

The transaction fee on the Ethereum network will be calculated using the following formula:

For example, at the moment the classic prices are as follows:

  • 21010 Gas is spent,
  • price per unit of gas is 6 Gwei, or 0.000000006 ETH,
  • In total, 126060 Gwei, or 0.00012606 ETH, will be required for the transaction.

Recommended gas prices (based on current network conditions):

  • for a low priority transaction (up to 30 minutes) - 1 Gwei
  • standard time (up to 5 minutes) - 3 Gwei
  • high priority, transaction in the next block (less than 2 minutes) – 6 Gwei

The user sets the price independently, but often everyone trusts the default settings in the wallet. Sometimes the price can be reduced if the transaction does not need to be carried out very urgently. The safest lowest price for June 2022 is listed above.

To further reduce the transaction fee in Ethereum, you can set the price for 1 gas in the region of 1–2 wei (the smallest part of Ether). As long as the mempool is not overloaded and the blocks are not filled to capacity (maximum capacity is 6,700,000 gas), such a transaction can also be withdrawn. But it can be risky. In addition, in MyEtherWallet and the official client you cannot set the price below 1Gwei through the slider. In MEW, the method works with “Offline transfer”.

EthGasStation is designed to increase the transparency of gas prices; there you can see all the current data on gas and transactions on the Ethereum network. This site helps you determine the current market price per unit of gas and avoid overpaying.

Located at ethgasstation.info

Transactions will be processed by miners until you run out of gas. The blockchain will record the transaction as “Failed” and the ETH will remain in the wallet because there is not enough gas to complete the transfer.

The gas used for a failed transaction will remain with the miners and you will NOT get it back. This is due to the fact that resources were wasted on performing the translation.

To correct a transaction with a low gas amount, you need to wait for it to fail and re-enter it, specifying the correct limit. Unfortunately, it is no longer possible to increase the limit during the process.

Again:

  • you need to indicate the gas limit with a margin,
  • different operations will use gas differently,
  • miners will not process the transfer once the limit is reached,
  • the gas remaining after the transaction is returned.

Running smart contracts on the network costs more because they perform different actions. Each smart contract is developed individually and adapted to the needs of the project. For example, for an elite project you can afford a gas price of $5, but for some messenger - not.

There are two main costs associated with sending and executing an Ethereum transaction:

  • Execution cost,
  • Transaction cost.

The cost of execution is primarily related to the storage of global variables and the processing power used for calculations.

Here are the prices for different operations:

  • Add or subtract two integers 3 gas
  • Multiply or divide two integers 5 gas
  • Compare two integers 3 gas
  • Create a new contract 32000 gas
  • Storing a 256-bit word 20000 gas
  • Save 1 MB (31250 256-bit words) 625000000 gas
  • Send 1 transaction 21000 gas
  • Include 1 byte (not zero) in transaction data 68 gas
  • Include 1 MB in transaction data 68000 gas
  • Contract deployment (first time) ~ 32,000 gas
  • Transaction input overhead (total) ~4 for 0-byte and 64 for non-0 byte inputs
  • Transaction cost under the contract ~ 32,000 gas

Also for individual operations:

A well-written contract will likely move the maximum amount of computation off-chain.

The overall size of the smart contract will play a role in the fee. If you can split the contract into smaller individual parts, it will reduce gas costs when dealing with them.

The most expensive operation in terms of gas is storage. Storing large amounts of data on the blockchain is usually not used: most often only the hash is stored. And shorten the code:

string STATUS = 'unknown status'; —>uint STATUS = 0; //T

You also need to remove as much duplication within structures as possible.

Developers need to be aware of these costs and design dApps with them in mind.

The principle of operation of ETC with gas for this fork remains the same as that of the original chain.

Each operation in the EVM has been assigned a specific amount of gas that it consumes. gasUsed - the sum of all gas for all completed operations. There is a table that gives an idea of ​​some of the prices. For Classic:

There is an API to evaluate gasUsed - evaluationGas.

It simulates the transaction entering the current block. But it also cannot guarantee exact calculations, only approximate costs.

In addition to broadcasting, GAS is used in the Neo network. But here he has a different concept and fundamental differences:

  • this is a separate token,
  • traded on the stock exchange independently,
  • can be obtained by storing NEO in certain wallets.

You can calculate your dividends using this calculator https://neotogas.com/

GAS is also used to conduct smart contracts on-chain. It is a transaction token. Its price is not calculated from NEO, but exists on its own.

In the NEO ecosystem, the token of the same name is used for governance. The online consensus algorithm is dBFT. Coins give you the right to vote.

GAS is transferred with each new block. More precisely, not the whole token, but a part of it.

NeoGas is generated every ~20 seconds in the amount of 8 pieces. All of them are distributed among NEO holders at this point in time.

After 2 million blocks, the amount of gas is reduced by 1 token.

DigixDAO uses DGD to manage the system, and the main token for purchase is DGX

IGNT is used for “proof of membership” in Ignite and was sold at the ICO. But it cannot be traded; it is used for management and participation in the rating. And the IGNITEX token is traded on the exchange and is available for exchange outside the system.

Power Ledger uses POWR and Sparkz: one token is pegged to fiat, used for transactions, and the other is used within the platform.

MintHealth pays VIDA as a reward, internal loyalty points, and MHST tokens are positioned as shares through which they attract capital to the project.

More guides, news and reviews on our website and channels:

Telegram / VKontakte / Twitter!

Ethereum Classic

The principle of operation of ETC with gas for this fork remains the same as that of the original chain.

Each operation in the EVM has been assigned a specific amount of gas that it consumes. gasUsed - the sum of all gas for all completed operations. There is a table that gives an idea of ​​some of the prices. For Classic:


There is an API to evaluate gasUsed - evaluationGas.

It simulates the transaction entering the current block. But it also cannot guarantee exact calculations, only approximate costs.

NEO Block GAS

In addition to broadcasting, GAS is used in the Neo network. But here he has a different concept and fundamental differences:

  • this is a separate token,
  • traded on the stock exchange independently,
  • can be obtained by storing NEO in certain wallets.

You can calculate your dividends using this calculator https://neotogas.com/


GAS is also used to conduct smart contracts on-chain. It is a transaction token. Its price is not calculated from NEO, but exists on its own.

In the NEO ecosystem, the token of the same name is used for governance. The online consensus algorithm is dBFT. Coins give you the right to vote.

GAS is transferred with each new block. More precisely, not the whole token, but a part of it.

NeoGas is generated every ~20 seconds in the amount of 8 pieces. All of them are distributed among NEO holders at this point in time.

After 2 million blocks, the amount of gas is reduced by 1 token.

Rating
( 1 rating, average 4 out of 5 )
Did you like the article? Share with friends:
For any suggestions regarding the site: [email protected]
Для любых предложений по сайту: [email protected]