<p>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.</p>

<p>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.</p>

<p>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.</p>

CC BY-SA 3.0
2015-06-17T23:46:26.350Z
2015-06-17T23:46:26.350Z
chriseth
<p>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)?</p>

<p>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?</p>

<storage><ethereum><smartcontracts>
In Ethereum smart contracts is it cheaper to keep all the data, or delete old data?
ThePiachu
# In Ethereum smart contracts is it cheaper to keep all the data, or delete old data?

(Asked by: username_0 on 2015-06-17)

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?

**Tags:** storage, ethereum, smartcontracts


---

## 1 answers

### Answer by username_1 on 2015-06-17. Score: 2

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.


---

