As I understand, Ethereum smart contracts can store data internally. I am wondering - is it cheaper for a smart contract to keep all of its data forever if it is keeping the data for any length of time, or does deleting unnecessary data from the contract after it has been used better (even though you have to pay for the operations)?

For example, if I have a contract that keeps a record of everyone that triggered it in the last day, does it make sense for me to remove that data the following day when it is no longer needed, or since the storage was already paid for, there is no point in deleting the old data?

1 Answer 1


You get a gas refund of 15000 for resetting a storage slot to zero, but you have to use this gas during the current transaction (more specifically, you get at most one half of the total spent gas as a refund). This means you can trade some cleanup with other operations, but you will never be returned such refunded gas in ether.

So the general idea is that if you e.g. have a crowdfunding contract, the function that checks whether its goal has been reached is cheap to execute even if it clears all the data and sends funds around.

But if all you do is to delete the data, you are probably better off just leaving it there, as the transaction that deletes the data will never be free.

Your Answer

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

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