eth: Gas

in #eth4 years ago

Content

After the contract is deployed, when you need to call the method of the smart contract, you only need to send a message (transaction) to the contract account. After the message is triggered, the code of the smart contract will be executed in the EVM.

Gas
Similar to cloud computing, occupying the resources of the blockchain (whether it is a simple transfer transaction or the deployment and execution of a contract) also requires corresponding fees (there is no free lunch, right!).
Ethereum uses the Gas mechanism for billing. Gas can also be considered as a unit of work. The more complex the smart contract (the number and type of calculation steps, the memory occupied, etc.), the more Gas is needed to complete the operation.
The number of gas required to run the contract for any particular contract is fixed and determined by the complexity of the contract.
The Gas price is set by the person running the contract when submitting the request to run the contract to determine how much he is willing to pay for this transaction: Gas price (priced in ether) * Gas ​​quantity.

The purpose of Gas is to limit the amount of work required to execute the transaction, while paying for the execution. When the EVM executes a transaction, Gas will be gradually consumed according to specific rules, no matter where it is executed, once the Gas is exhausted, an exception will be triggered. All state changes made in the current call frame will be rolled back. If there is gas remaining at the end of the execution, these gas will be returned to the sending account.