0

I have a doubt about the gas refund concept.

Imagine that I created a smart contract 1 month ago and now I want to call the SELFDESTRUCT because I want to send the current balance to an address and stop using that smart contract. So far I understood that the gas refund will be deducted from the total gas cost of the transaction that is calling the SELFDESTRUCT, am I right? If not, how is the gas refund "payed"?

0

2 Answers 2

2

I was trying to find a proper reference to this in Solidity docs, but for some reason I couldn't. The only proper thing I found was https://docs.soliditylang.org/en/develop/introduction-to-smart-contracts.html?highlight=selfdestruct#deactivate-and-self-destruct which doesn't say much about refunds.

So, you are correct. The refund is given in the same transaction, and it can't be stored. Also, the refund can never lower the transaction gas usage to under the basic cost of 21000. This is correct for any refund.

1
  • Thanks for the answer, I had problems looking for this on the docs too Jan 31, 2021 at 13:39
1

The concept is that it will refund you UP TO a maximum of 50% of the gas used in the transaction.

So if it costs you 100,000 gas to execute a transaction the refund you receive will be a maximum of 50,000 depending on what you destroy.

Another thing is that the gas limit of the transaction must be set to the full 100,000 even if the transaction only ends up costing you 50,000. The refund is only applied at the end of the transaction, so the full gas must be made available in order to execute the full transaction.

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