Gas - Reading Assignment

1.Gas is what is used to calculate the amount of fees that need to be paid to the network in order to execute an operation. For example, a simple operation like if(var > 1) may cost 1 gas, but a more complex operation to store a variable could cost 100 gas.The cumulative sum of all the operations is the total gas cost for the transaction.

2.In order to get an operation done in Ethereum, the sender of the transaction must specify a gas limit before they submit it to the network. The gas limit is the maximum amount of gas the sender is willing to pay for this transaction.

3.The transaction will be rejected.If an operation runs out of gas, then it is reverted back to its original state like nothing actually happened, however, the operation generator must STILL pay the miners the fee for their computational costs and the operation gets added to the blockchain (even if it has not been executed).

  1. No. The minimum gas limit for transaction is 21000 + the amount to execute any fallback functions if it’s sent to a contract, but the actual blocks also have a gas limit that specifies the maximum amount of gas all transactions in the block can consume.

  2. Gas Price is the price of each gas unit measured in a fractional amount of ether, typically gwei. Gas price varies, but 20-30 gwei is average as of writing this.

1 Like

The cumulative sum of all the operations is the total gas cost for the transaction.
2.
It shows the max amount of Gas what you willing to spend on the transaction.
3.
Then the transaction will fail, and the miner keeps the fee…
4.
Extra gas are refunded automatically.
5.
Basically unit. Gas price is measured in ether, using the unit of gwei.

1 Like

Great answers @KryptoDr
But for the 5th one , the smallest unit is actually wei not Gwei :wink:

How do we calculate the total gas cost for a transaction?
Transactions on the Ethereum network require fees in the form of gas. The amount of gas depends on the amount of computation required to complete the transaction.

What is gas limit?
Gas Limit is the maximum amount of gas allotted to the transaction, 21000 being sufficient for simple transfers and much higher amounts for transfers to smart contracts like those in ICOs.

What happens if we specify a gas limit that is too low?
Insufficient gas in the Gas Limit will result in a failed transaction, the fee paid will be lost, but the ether transferred never leaves the wallet since the blockchain was never updated.

What happens if we specify a gas limit that is too high and therefore not consumed fully?
All unused gas never leaves your wallet. So if you go to MyEtherWallet, send 1 ETH to our donation address, and use a gas limit of 400000, you will receive 400000 - 21000* = 379000 back. However, if you were sending 1 ETH to a contract, and your transaction to the contract fails, you will use the entire 400000 and receive nothing back.
*21000 is the standard gas limit for regular transactions.

What is a gwei?
Gwei is a very small amount of ethereum coin used to calculate transaction fees for sending ethereum to another. One ethereum coin is worth 1 billion (1,000,000,000) gwei.

1 Like
  • How do we calculate the total gas cost for a transaction?
    The cumulative sum of all the operations is the total gas cost for the transaction.

  • What is gas limit?
    This corresponds the the MAXIMUM amount of gas you are willing to spend on the transaction.

  • What happens if we specify a gas limit that is too low?
    Providing too little gas will result in a failed transaction

  • What happens if we specify a gas limit that is too high and therefore not consumed fully?
    Extra, unspent gas is refunded automatically

  • What is a gwei?
    Gas price is usually some amount of gwei. Wei is the smallest unit of ether and gwei is simply 1000000000 wei.

1 Like
  1. How do we calculate the total gas cost for a transaction?
  • You take the Gas spend for each particular transaction and combine to give a total transaction or execution cost.
  1. What is gas limit?
  • The maximum amount of Gas spend you are willing to pay for the transaction to be completed
  1. What happens if we specify a gas limit that is too low?
  • The transaction may not complete resulting in either the funds transfer or smart contract not being executed. The transaction costs you did allocate would not be refunded but the main funds would not have moved from your wallet.
  1. What happens if we specify a gas limit that is too high and therefore not consumed fully?
  • Unspent Gas will be refunded
  1. What is a gwei?
  • Its the unit that Gas price is measured in and comes from the smallest unit possible of Ether which is 1 wei. 1 Gwei is equal to 1 billion Wei
1 Like

1. How do we calculate the total gas cost for a transaction?
The total gas cost is calculated on the basis of the computational power needed for executing the requested code.
2. What is gas limit?
It has to be set with the smart contract and means the maximum amount of gas that can be spent for the transaction on EVM.
3. What happens if we specify a gas limit that is too low?
The gas is spent but the transaction will not be executed.
4. What happens if we specify a gas limit that is too high and therefore not consumed fully?
Unspent gas will be refunded
5. What is a gwei?
One gwei is basically one Ethereum. “Wei” is the smallest fraction of ETH (one billionth) and the prefix G multiplies it for one billion.

1 Like
  1. How do we calculate the total gas cost for a transaction?
    The price of gas is calculate in ether and specifically in wei or gwei and is determined by the user. Gas prices vary depending on the complexity cost of the tx. Current gas prices at any given time can be seen on Etherscan or Eth gas station.
  2. What is gas limit?
    The gas limit is the maximum amount in GWEI allotted to a particular set of commands to be executed on the EVM.
  3. What happens if we specify a gas limit that is too low?
    The transaction will start, but can run out of gas if miners do not complete and add to the block. The participant would lose the gas and fallback fees.
  4. What happens if we specify a gas limit that is too high and therefore not consumed fully?
    The extra gas will be refunded to the sender.
  5. What is a gwei?
    Gwei is a very small amount of ethereum coin used to calculate transaction fees for sending ethereum to another. One ethereum coin is worth 1 billion (1,000,000,000) gwei.
1 Like
  1. The total gas depends on the amount of computation required to complete the transaction.

  2. Gas Limit is the maximum amount of gas allotted to the transaction, 21000 being sufficient for simple transfers and much higher amounts for transfers to smart contracts like those in ICOs.

  3. If the gas price specified is too low, this will result in a failed transaction, the fee paid will be lost, but the ether transferred never leaves the wallet since the blockchain was never updated.

  4. If the gas price specified is too high, the extra unspent gas is refunded automatically after the transaction is complete.

  5. Gwei is 1 Billion wei. A Wei is the smallest unit of Ether. Gas is measured in Gwei.

1 Like
  1. How do we calculate the total gas cost for a transaction?
    total gas cost = cumulative sum of the gas cost of each machine operation

  2. What is gas limit?
    The maximum price one is willing to pay for a transaction, thus the transaction fee.

  3. What happens if we specify a gas limit that is too low?
    It results in a failed transaction and the fees are kept by the miner.

  4. What happens if we specify a gas limit that is too high and therefore not consumed fully?
    Unspent gas is refunded automatically.

  5. What is a gwei?
    1 million wei. The unit in which gas is usually specified.
    Transaction price = gas price * gas limit

1 Like

1. How do we calculate the total gas cost for a transaction?
The total cost of gas for a transaction is the cumulative sum of all operations.

2. What is gas limit?
This is the higher amount of gas you are ready to spend on a transaction.

3. What happens if we specify a gas limit that is too low?
If the specified quantity of gas is too low, the execution of the transaction will start but will be interrupted before the end due to insufficient gas. The amount of gas used will be lost even if the transaction is not completed. The amount of ether will remain in the wallet and the transaction will never appear in the blockchain.

4. What happens if we specify a gas limit that is too high and therefore not consumed fully?
If the gas limit is too high, the unspent gas will be automatically refunded.

5. What is a gwei?
A gwai = 1 000 000 000 wei and a wei is the smallest unit of ether. Gwei is the most commonly used ether unit because “gas” prices are easily specified in gwei.

1 Like
  1. Summing the Gas cost for each single line of code
  2. It is the maximum cost of gas a user is willing to pay for a transaction or deployment of a smart contract.
  3. The transaction will stop mid-executing and thus will be discarded, the node will keep the fees but the Ether will never leave the wallet.
  4. The unused Gas will be refunded to the issuer of the transaction.
  5. Wei is the smallest amount of Ether and gwei is 1000000000 wei
1 Like

1. How do we calculate the total gas cost for a transaction?

Quite close sir, but the cost is not for each line of code, it’s for the summation of each operation that will be made on the transaction.

Here is a sheet that will give you a better understanding: Gas Cost.

Hope this gives you a clear view of the subject, keep learning! :slight_smile:
If you have any doubt, please let us know so we can help you!

Carlos Z.

How do we calculate the total gas cost for a transaction?
All transactions, from simple transfers to ICO smart contracts, require some amount of operations to perform. Each of these operations has an associated cost in gas
What is gas limit?
It corresponds to the maximum amount willing to be spent on a transaction
What happens if we specify a gas limit that is too low?
You will not get back the ether price on gas spend, however the blockchain doesn’t register the transaction so the ether doesn’t leave the wallet.
What happens if we specify a gas limit that is too high and therefore not consumed fully?
In this case the miners only get paid for the actual gas consumed by a transaction so they will be unlikely to pick it up. The blocks have a gas limit that specifies the maximum amount of gas that all transactions in the block can consume. This is comparable to Bitcoin’s block size in bytes, but ether miners have the option to increase or decrease the gas limit of blocks so that they are propagated quickly.
What is a gwei?
It is a unit of gas broken down further into 1000000000

1 Like
  1. The cumulative sum of all the gas costs of all operations is the total gas cost for the transaction.
  2. The maximum amount of gas I am willing to spend on the transaction.
  3. The transaction will start to be executed, but will eventually run out of gas and be stopped.
  4. If the gas limit is too high, the unspent gas will be automatically refunded.
  5. A gwei is 10^-8 ETH or 10^10 wei, the smallest unit of counting ETH.
1 Like

1. How do we calculate the total gas cost for a transaction?
This is the cumulative sum of all the operations.
2. What is gas limit?
The maximum amount of gas that can be spend on a transaction.
3. What happens if we specify a gas limit that is too low?
This will result in a failed transaction but paid fees are kept by the miner.
4. What happens if we specify a gas limit that is too high and therefore not consumed fully?
It wil be returned automatically.
5. What is a gwei?
1000000000 wei. Wei is the smallest unit of ether.

1 Like
  1. How do we calculate the total gas cost for a transaction?

The cumulative sum of all the operations is the total gas cost for the transaction.

  1. What is gas limit?

MAXIMUM amount you are willing to spend to execute the transaction.

  1. What happens if we specify a gas limit that is too low?

Your transaction will start to be executed but will eventually run out of gas and be stopped. When this happens, you will lose the transaction fees but will retain the main sum.

  1. What happens if we specify a gas limit that is too high and therefore not consumed fully?

This will fill up the block gas limit set by miners, but isn’t computationally-dense enough for miners to want.

  1. What is a gwei?

as price is usually some amount of gwei. Wei is the smallest unit of ether, and gwei is simply 1000000000 wei.

2 Likes
  1. How do we calculate the total gas cost for a transaction?
    The total Gas cost is calculated by adding up all the pre-determined costs per operation but the transaction cost is subject to a minimum of 21000 Gas plus the cost of any fall back functions if its sent to a contract.
  2. What is gas limit?
    Gas Limit is the maximum amount of gas that you are willing to pay for a transaction.
  3. What happens if we specify a gas limit that is too low?
    The transaction will start but then fail and any Ether spent on used gas will not be returned although no transfer of Ether will take place because the transaction failed and was not added to a block.
  4. What happens if we specify a gas limit that is too high and therefore not consumed fully?
    Because Ethereum blocks have a gas limit size, it is likely that the transaction will stay in the Mempool as Miners will not want to deal with the transaction because it is not computationally dense enough. This is because the miners only get paid for the actual gas consumed to perform a transaction.
  5. What is a gwei?
    A Gwei is a fractional part of Ether in that is represents 1000000000 wei. Wei is the smallest unit of Ether.
1 Like
  1. Different actions have different prices, add them
  2. The max amount of gas we are willing to spend on a tx
  3. The tx gets rejected
  4. The fee gets lost but the tx value never leaves the wallet
  5. a billion wei is one gwei, and wei is the smallest unit of ether
1 Like

1
By summing all the fees due for computational operations (Solidity commands) made by the EVM when it executes the requested code / transaction.

2
The setting (in Gwei) the user choose as maximum fee to interact with the Ethereum bc.

3
The transaction is not performed and no gas spent.

4
The exceding gas is returned in the wallet.

5
It’s the notation to indicate gas fees. A fraction of the Ethereum coin. 1 Gwei = 1 ETH/1000000000

1 Like