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
The sidebar is recommended
- To learn blockchain technology, let's build a group school district blockchain technology
- Review of dimitra and Morpheus AMA, global blockchain agricultural technology platform
- Bitcoin public key principle
- Blockchain application series - did
- Bitcoin series - using docker to build BTC private chain
- Bitcoin series - BTC synchronous public chain, test chain and private chain
- Bitcoin series - BTC compilation and installation
- Ethereum series - Web3 js
- Experience - deploy Ethereum private chain (POA)
- Experience part - deploying Ethereum private chain (POW)
guess what you like
-
Ethereum series - Smart contract development and commissioning
-
Ethereum series - DAPP development three swordsman
-
IPFs series - combination of IPFs and blockchain
-
How can the Internet of things, big data, cloud computing, blockchain and artificial intelligence be combined to promote the development of digital economy?
-
The form of story telling tells you what is server, cloud deployment, virtualization, artificial intelligence, blockchain, cloud computing, big data and privacy computing
-
Open source Hongmeng, metauniverse, blockchain, open source collection | alot open source science and technology festival and openharmony technology forum are in hot registration
-
Bankless year-end summary: encrypted network will subvert the old power system
-
The other side of Dao: bribery in the chain and the rise of dark Dao
-
The first 3D chain game (CSC) of metauniverse concept seeks token in encrypted world and blockchain game
-
Metauniverse 3D [NFT] arrg mobile game of metauniverse blockchain [Curtis sword]
Random recommended
- It is said on the Internet that three arrows bought "Adidas and gear", which is actually a fraud
- How will the global network and metauniverse affect international politics?
- GIS + blockchain, a new application scenario of geospatial data, is expected in the future
- The demand for NFT, a clothing luxury brand, has soared, and metauniverse may provide opportunities for transformation
- Curtis sword CSC coin star "Q coin mode" will be launched in January
- Adaoracle ecology and its decentralized Oracle network promote the development of blockchain
- a16z:Web3. 0 ecological panorama
- Development and application of blockchain in food industry
- Chat blockchain (III)
- Ethereum smart contract - building the basic environment
- Founder of ENS: not only Eth, to be the domain name service provider of every digital resource in the world
- A piece of land is 32 million. Why do real estate tycoons buy land in the virtual world?
- Three minutes to understand why arbitrum TVL can lead in layer2
- 13th anniversary of bitcoin white paper, 13 key knowledge points
- From didi to bitcoin, towards a new era of zero friction economy
- Randomness in bitcoin
- Blockchain private Chain NEW
- Blockchain private chain
- Blockchain game: unsustainable or is the future coming?
- Chat blockchain (IV)
- What else does the meta universe lack? Immersive sound hasn't been customized for avatars yet
- Ethereum web3js calls smart contract and does not return transaction hash
- How is Block 0 confirmation implemented
- What are the testing tools for Ethereum smart contract?
- Why can't I display pictures in my wallet when I bind the tokenid with the hash returned from uploading to IPFs?
- TransferHelper: TRANSFER_ FROM_ FAILED
- How to solve the problem of solidness version and package?
- How can a token in Tron wave field and TRX Group LP, pair contract obtain the quantity of a token through LP?
- Using openzepplin library contract
- What was the initial POS consensus agreement?
- Introduction to blockchain
- What progress has filecoin made so far?
- What are the impacts of Libra compared with DCEP?
- What is a token in the blockchain?
- Is there any material that can make Xiaobai learn blockchain quickly?
- How to validate smart contracts?
- Can Ethereum's official wallet password be restored if you forget it?
- What is BiP
- How to convert byte type to integer uint in solidity
- Can this be used in the smart contract constructor?