0

I have (mulicollatral)Dai v2 in the wallet and I want to set the minimum possible gas limit such that my send transaction don't fail. Thanks

3
  • 1
    1. It doesn't matter if you put a little more, because you'll get it back (though a lot more might cause miners to avoid it). 2. It may change from one transaction to another, depending on the state of the contract. 3. We cannot answer that without seeing your code. 4. It also depends to a certain extent on the compiler that you're using. 5. You can simply call estimateGas before sending the transaction. That's the best (and most recommended) way, because it mostly gives you the exact amount of gas required. – goodvibration May 9 '20 at 18:39
  • amazing answer, thanks! – lebed2045 May 10 '20 at 6:47
  • I'll make it into an answer then. – goodvibration May 10 '20 at 6:48
1
  1. It doesn't matter if you put more than required, because you'll always get it back

  2. There is no single answer to your question, because the required amount of gas may change from one transaction to another, depending on the state of the blockchain (i.e., the value of every state variable involved in the transaction)

  3. It also depends to a certain extent on the compiler that you're using, because different compilers may generate different bytecodes

Note that you still want to use the minimum amount of gas required, because miners choose highest-price/lowest-limit first, so your transaction will likely execute faster if you choose a smaller limit. For that, you can simply call estimateGas before sending the transaction, which will give you the exact amount of gas required in most cases.

10
  • 1. True. However it does in the situation where I have 0 Ether wallet which holds erc20 token. So I want to send minimum amount of Ether which would be sufficient to withdraw erc20. – lebed2045 May 11 '20 at 11:04
  • 2. True, however there's a minimum amount of gas limit == maximum possible gas consumption across of possible configurations. Basically the worst case scenario, like big O notation for the complexity measurement. – lebed2045 May 11 '20 at 11:06
  • @lebed2045: 1. Of course. I forgot to mention that using the minimum is beneficial not only because miners choose highest-price/lowest-limit first, but also because it allows you to have no more than that minimum in your wallet. In other words, when you specify a large limit, even if the actual requirement is lower than that limit, you still need to have it in your wallet, otherwise the transaction will not be initiated. However, in your specific case - a 0 Ether wallet - you won't be able to execute the transaction regardless of all of that, because any transaction requires at least 21000 gas – goodvibration May 11 '20 at 11:19
  • @lebed2045: 2. That's wrong. Inside an ERC20 transfer function, the author of the contract can do pretty much whatever they want to, which means that any gas-consumption is possible (up to the network's block-limit of course). – goodvibration May 11 '20 at 11:23
  • 1. Yes, and the question is: how much Ether should I send there that it would be sufficient to withdraw erc20 and minimize amount of Ether I send given current GasPrice. – lebed2045 May 12 '20 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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