4

I'd like to make estimations of the cost of an application, and one of the things I need is the price to store n kB of data on a contract. In ether and in USD.

Where could I find rates or prices of raw data storing? Sites showing ETH<->USD prices are rather easy to find but I can't seem to find an approximation of how much it would cost to store a certain amount of data.

The rates change pretty fast and a 2 years-old answer with "Right now, the fees are around ..." is helpful, but insufficient. Where could I get reliable, recent information about the rates?

Subsidiary question: When we store data on the blockchain, I understand that there's a price in gas for the transaction, and another price to actually put data in the blockchain (long term). Am I correct?

marked as duplicate by Jitendra Kumar. Balla, Achala Dissanayake, Richard Horrocks, Ismael, flygoing Feb 27 '18 at 16:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • I edited to show how the linked answer absolutely does not answer my question, but I didn't convince enough, I guess. I want current price, answer says "right now, gas price is around..." (2 years ago) and gives no clue about where to find current prices. As I stated in my own answer, most of the information I needed was as that Gas station site. – Teleporting Goat Feb 28 '18 at 9:51
6

Currently the only times you pay for storage are when you write it and when you read it back. There is no ongoing cost for storage, although there have been some discussions about whether there should be, and it is possible that there will be in future.

As with other transaction costs, the cost for storage is set in gas. This means that you need to multiply the cost of each operation in gas by the price of gas at the time you store something or read it back. Since the gas price is not known in advance, you can't be sure in advance how much it will cost to read and write storage in future in ETH or USD.

The costs of storage operations in gas are:

20,000 gas when a value is set to non-zero from zero; 5,000 gas when writing to existing storage or setting a value to zero; and a 15,000 gas refund when a non-zero value is set to zero.

These costs are set per 32-byte word that is written to storage. If your fields do not round cleanly into 32-byte sections there will be some additional overhead, although the compiler does a reasonably good job at optimizing it.

There is also a minimum base cost for each transaction of 21,000 gas.

Note that unless your contract actually needs to process the data in storage, it is normally better to store the data in IPFS, then just store its IPFS location in the contract. It is also possible to store data on the blockchain by writing to event logs, which is substantially cheaper than contract storage.

  • Thanks, I didn't know about the 5k and 15k. But if you clear you data, does it cost 5k minus 15k that are refunded, or do you just get 15k in refund (making your total expenses to 5k) ? – Teleporting Goat Feb 26 '18 at 9:15
  • 2
    You pay 5k for the write that clears the storage, then you get the 15k back at the end, resulting in a net profit of 10k for that particular operation. However, see the answers to this question for nuances about gas refunds - for example, there's a cap on how much can be refunded, as a proportion of how much is spent: ethereum.stackexchange.com/questions/594/… – Edmund Edgar Feb 26 '18 at 10:38
1

Well, it looks like no matter how long I search, I only find what I'm looking for after asking my question.

According to this question, "the fee is 20k gas to store a 256 bit word."

Assuming this hasn't changed, I'm taking the liberty of updating the "right now" part, as the question is 2 years old. Gas price seems to be around 3 GWei, not the 50 GWei given in the answer.

I got the information from EthGasStation, which gives most of the information I needed.

According to their calculator (and my calculations), 1 kB needs 625000 gas and with current gas and ether prices, 1 kB = $1.57875 (0.001875 ETH)

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