1

Suppose a smart contract external function uses very much gas, but refunds (with .transfer()) the used gas to the caller.

Question: Can it be called with a small amount of gas despite it uses much?

Moreover, can such a function be called by a user having zero on his account? (The gas is refunded to him, so I am unsure.)

3
  • Can it be called with a small amount of gas despite it uses much? - no. – goodvibration Aug 29 '20 at 9:45
  • can such a function be called by a user having zero on his account? - no. – goodvibration Aug 29 '20 at 9:46
  • Upvoted the Q&A but already has answers. – eth Aug 29 '20 at 11:32
2

Can it be called with a small amount of gas despite it uses much?

No, gas is refunded at the end of transaction execution. If the transaction runs out of gas before that, the transaction is reverted, and no gas will be refunded. You always need to provide enough gas for transaction execution, without any gas refunds.

Can such a function be called by a user having zero on his account?

It's not possible to call a function with no Ether balance. The base cost for any transaction is 21,000 units of gas, which is always required. When sending transactions to a contract, the cost of the contract execution is added on top of that.

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