current position:Home>What does gas in Ethereum mean?

What does gas in Ethereum mean?

2022-02-03 20:47:02 Q & A of Denglian community

In Ethereum gas ( gasoline ) What does that mean? ?




Take the answer 1:

I want to use an Ethereum application that needs ”gas” To run the , What is? gas, Where do I get gas?

understand gas

“gas” Is the name of a special unit used in Ethereum . It measures how much an operation or group of operations needs to be performed ” Work ” The amount : for example , Calculate a Keccak256 Cryptographic hash function , Each time you calculate a hash, you need 30 individual gas, Plus every 256 Bit hashed data costs more 6 individual gas. Each operation performed through transaction or contract on Ethereum platform will consume a certain amount of gas, Operations that require more computing resources are more expensive than those that require less computing resources gas more .

gas Why is it important , Because it helps Ensure that transactions submitted to the network pay the appropriate fee . By requiring the transaction to perform each operation for it ( Or contract execution ) pay , It can ensure that the network will not be deadlocked by performing a lot of intensive work that is of no value to anyone . This is different from the strategy of bitcoin transaction fees , The latter is based only on the kilobyte size of the transaction . because The etheric fang Allow any complex computer code to run , Even very short code can lead to a lot of computing work . therefore , It's important to measure the workload directly , Instead of just determining the cost based on the length of the transaction or contract .

payment gas

that , If gas It's basically a transaction cost , How to pay for it ? This is where it gets a little tricky . Even though gas Is a unit of work that can be measured , But there is no practical gas Tokens, (Token) Come on . in other words , You can't have 1000 individual gas. contrary ,gas Exists only in TaiFang virtual machine Inside , As a count of how much work is being performed . When it comes to actual payment gas, Is to charge a certain amount of ether ether( Ethereum network native token ) As a transaction fee , User rewards miner production block .

This may seem strange . Why can't you use ether directly (ether) To measure costs ? The answer is that Ethernet is like bitcoin , The market price changes rapidly ! But the calculation cost will not rise or fall just because of the change of ether price . therefore , It is helpful to distinguish the calculated price from the ether price , such , Every time the market fluctuates , Operating costs do not have to change .

The terminology here is a little messy .EVM The execution of the needs to consume gas Of , and gas Self use gas Price ( In ether ) To measure . Each transaction must be designated as a willing unit gas Paid gas Price (gas price), This is a combination of the two ,*gas Consumption gas Price = transaction cost **. This allows the market to determine ether prices and calculate operating costs ( With gas To measure ) The relationship between .

Although it's tricky , But understand gas Consumption and gas Price differences are important , It brings beginners the most confusing thing in Ethereum trading : The transaction is exhausted gas(out-of-gas) Different from the fact that the transaction does not cost high enough . If I set it in the transaction gas The price is too low , No one will run my deal the first time , Miners don't pack them into blockchains at all . however , If I provide an acceptable gas Price , Then trading has too much computational work ( Consume too much gas), Merged gas The cost exceeds my additional cost ,gas Will be spent by miners and stop processing transactions , The changes made will also be restored , But it still regards it as ” Failed transactions ” Included in the blockchain , Miners charge for it . This seems harsh , But when you realize that the real job of a miner is to perform calculations , It can be seen that they will never recover these resources . therefore , Even if it is consumed by poorly designed transactions gas, It's Fair for you to pay for the work done by the miners .

Provide great gas It's also different from offering too high gas Price . If you set a very high gas Price , You will eventually pay a lot of ether for a few small operations , It's like setting up a bitcoin transaction with ultra-high transaction cost . The transaction will certainly be given priority , But your money is gone . however , If you provide a normal gas Price , And provide gas The quantity is greater than the cost of the transaction gas Need more , The excess amount will be returned to you . The miners only charge you for your actual work . You can take gas The price is regarded as the miner's hourly wage , take gas The consumption is regarded as the working time completed .

gas There are many other subtleties , But these are the basics you should know !Gas Is to enable the Ethereum network supporting complex computing ” Security ” The key to the job , Because any runaway program can only continue when it requests funding from the operator . When money is insufficient , The miners stopped working . and Mistakes made in the program will only affect those who pay to use it —— Other parts of the network will not have performance problems due to this error . Without this key technology , The idea of a universal blockchain will be completely impossible .

Conclusion

  • gas Is the way to calculate the cost .
  • cost (fee) Still in ether (ether) payment , But it's connected to gas Different .
  • gas Consumption is the amount of work performed by the transaction , Such as labor hours 、 Kilometers traveled by the vehicle , and gas The price is similar to the hourly wage you pay to complete the work . The combination of the two determines the total transaction cost .
  • If gas The price is too low , No one will handle your deal .
  • If your gas The price is normal , But your deal is gas Consumption exceeds ” The budget ” Will cause the transaction to fail , Still the most failed transactions enter the blockchain , And can't recover the expenses paid .
  • It ensures that no program can run forever , And people will run their code carefully . It protects miners and users from bad code .

Original question and answer link




copyright notice
author[Q & A of Denglian community],Please bring the original link to reprint, thank you.
https://en.netfreeman.com/2022/02/202202032046575757.html

Random recommended