Ethereum gas, gas limit, gas price
This video explains what Ethereum gas is and why you need to specify a gas limit and gas price when you make a transaction.
When a solidity contract is compiled it is converted into a sequence of operation codes also known as opcodes.
Opcodes are referenced by their mnemonic names such as ADD (for addition) or MUL (for multiplication).
All opcodes and their descriptions are available in the Ethereum yellow paper:
ethereum.github.io/yellowpaper/paper.pdf
Side note:
Byte codes are similar to opcodes but are represented by hexidecimal numbers.
The Ethereum Virtual Machine (EVM) executes the byte codes.
Each opcode has a fixed amount of gas assigned and is a measure of computational effort.
For example ADD requires 3 gas units, calculating SHA256 requires 60 gas units.
Gas is the execution fee, paid by the sender of the transaction that triggered the computation.
By default the minimum gas limit for all transactions = 21000 gas
Sending ether from one account to another = 21000 gas
Interacting with a smart contract = 21000 gas all executed opcodes gas
For users it is impossible to know how much gas a transaction will actual require.
When executing a transaction a user can specify the maximum amount of gas it is willing to spend on the transaction.
This can be done in the gas limit field.
If the transaction is executed but is exceeds the gas limit, all changes are reversed but the user will still have to pay for performed computation, which is the gas limit.
If the transaction is executed but requires less gas than the gas limit, the user will only pay for the actual gas used.
It is not recommended to specify a large gas limit.
If you interact with a smart contract and the contract contains a bug you may exceed your gas limit.
Total fee = the total amount of gas used x gas price
The gas price is not fixed.
The user decides which gas price it is willing to pay in Gwei/gas.
The mainnet current gas price and block gas limit can be found at: ethstats.net
The rinkeby testnet current gas price and block gas limit can be found at: www.rinkeby.io
Miners prefers transactions with a higher fee.
Transactions with a lower fee will take longer to be included in a block.
Side note:
A block also has a gas limit field.
It defines the maximum amount of gas all transactions in the block combined are allowed to consume.
This block gas limit determines the maximum number of transactions within the block.
This block gas limit is not fixed.
The block gas limit is set by miners.
If the block gas limit is increased more transaction fees they get, but the more bandwidth and computing they would have to do.
Check out all my other Ethereum related tutorial videos:
goo.gl/eNJVXe
Subscribe to my YouTube channel:
goo.gl/61NFzK
The presentation used in this video tutorial can be found at:
www.mobilefish.com/developer/blockchain/blockchain_quickguide_ethereum_related_tutorials.html
The DemoContract.sol used in the video:
www.mobilefish.com/download/ethereum/DemoContract.sol.txt
To interact with the DemoContract.sol use the demonstration Ethereum Dapp (using Javascript Promises):
www.mobilefish.com/download/ethereum/DemoDapp.html
#mobilefish #howto #ethereum
0 комментариев