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:
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: https://ethstats.net
The rinkeby testnet current gas price and block gas limit can be found at: https://www.rinkeby.io
Miners prefers transactions with a higher fee.
Transactions with a lower fee will take longer to be included in a block.
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:
Subscribe to my YouTube channel:
The presentation used in this video tutorial can be found at:
The DemoContract.sol used in the video:
#mobilefish #howto #ethereum