8

I have got 2 questions actually:

  1. How to determine the gas price? Metamask fills this in for me, but it is always too low when I click on submit. Basically all values on ETH Gas Station seem too low? How much Gas Limit to put in?

  2. I've gotten a transfer through using high values. but it failed nonetheless. It seems I now lost 0.0105 Ether ($13.66)? Is there a way to get this back? Is there a way to NOT make these mistake? It is truly a very high learning curve (and costly).

See: https://etherscan.io/tx/0x2d68ca04e623509c05713a8b80c857e49cc80d3a71aadebd0aca7eb2511c57cd

Thanks for any assistance.

4 Answers 4

2

I think you got something backwards... you set a gas limit of 42000, which was evidently insufficient. You should pretty much never adjust the gas limit, as it's very accurately determined ahead of time. MetaMask should be getting the gas limit right for you.

You also set a very high gas price: 250 gwei, when https://www.ethgasstation.info/ says 80 gwei should get your transaction processed within 2 minutes.

No, there's no way to get back the ether you paid for that transaction.

In the future, let MetaMask choose the gas limit, and set the gas price by checking https://www.ethgasstation.info/.

EDIT

I should note that an out of gas error can also occur when something else goes wrong in the transaction. Some kinds of errors can cause all the gas to be consumed. (E.g. an assert in the code.)

3
  • Hi there, Thanks for that knowledge. Metamask gives me gas prices as preset, they are pretty close to what gas station is suggesting. However Gas Limit always starts at 0, so how do I determine what limit to use? Is there such a thing as setting the Gas Limit too high?
    – J S
    Jan 10, 2018 at 21:46
  • That's very strange. MetaMask should be able to properly estimate the gas you need. The only downside to setting a high gas limit is that if an error (e.g. an assert) causes all of the gas to be consumed, then you'll end up paying more than you needed. For this particular transaction, I would think that 100,000 is plenty high, but I'm confused as to why MetaMask would be getting this wrong. Do you see any error messages?
    – user19510
    Jan 10, 2018 at 21:50
  • No error message other than that it failed. It was actually my first transaction that didn't fail immediately due to 'intrinsic gas too low'. Unfortunately MetaMask didn't fill in 21000 gas limit, it just let's you add the value yourself from 21000 till infinity almost. Either way, thanks for the help - wish I read a guide first.
    – J S
    Jan 10, 2018 at 22:29
2

If you are looking for the gas cost of a historic transaction like I was, here's your answer.

gasCost(tx) = gasPrice * gasUsed

You can use web3 to get the 2 pieces of information needed, but you'll make 2 different calls:

web3.eth.getTransaction(txHash)

returns an object that includes gasPrice.

web3.eth.getTransactionReceipt(txHash)

returns an object that includes gasUsed.

With these two pieces combined, you have the cost of gas for a specific historic transaction.

1

Gas limit can (conceivably) be set to whatever value you want--the transaction will use whatever gas it uses and any amount of gas over what is used will be refunded---except---and this is a very important exception--if the transaction fails (because of an assert or throw for example).

If the transaction throws, you will not get an error message of any kind other than 'out of gas,' because what happens when a throw or assert hits is all the remaining gas (up to the gas limit) is consumed and the transaction returns (that's why I said gas limit matters--it matters when it fails--it doesn't matter when it doesn't). But @smarx is right--let Metamask make the setting.

Once you've spent the gas, you can't get it back. Think of it this way--the machine that mined the block did the work to decide if the transaction succeeded or not. That machine (i.e. the miner) should not be penalized because you ran a function that failed. The function ran--that cost the miner money--he/she should get paid.

The total cost of the transaction (just FYI) is gas used * gas price.

0

If you want to calculate the block transaction fee, you can calculate it as follows:

  1. eth_getBlockByNumber get block info.
  2. Get the above block info Get the hash of each transaction.
  3. eth.getTransaction get gasUsed.
  4. eth_getTransactionReceipt get gasprice.
  5. gasUsed * gasPrice get transaction fees.
  6. Add up all transaction fees.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.