68

Whatever is stored in the blockchain is immutable which means I can fetch this data back in the future. As of today (2016-feb),

  • How does one store a 1kb, 10kb, or 100kb or arbitary data/text in the ethereum blockchain? What is the code needed to do this?

  • Once stored how do you download the data back onto your desktop?

  • How much would this cost exactly in ether/gas/fiat at todays prices?

1
  • It's better to split this up in multiple questions on stack exchange. Asking many questions in 1 thread is usually not good.
    – mesqueeb
    Commented Sep 27, 2018 at 13:22

5 Answers 5

6

Here is an article to describe everything about gas and how to calculate it.

Suppose, we are adding two numbers and for that the contract must do the following actions:

Storing 10 in a variable. Let’s say this operation costs 45 gas. Adding two variables, let’s say this costs 10 gas. Storing the result which again costs 45 gas.

Suppose the sender specifies a gas limit of 120 gas.

The total gas used by the miner to run the computation is (45+10+45) = 100 gas.

The fee that is owed to the miner, assuming 1 gas costs 20 Gwei, is (100 * 20 Gwei) = 0.000002 ETH.

And here you can get GAS calculations

1
  • This answer is underrated.
    – Mowzer
    Commented Jun 21, 2019 at 19:35
86

tl;dr: $0.076/KB or $76,000/GB

According to the yellow paper, the fee is 20k gas to store a 256 bit word. A kilobyte is thus 640k gas.

Gas right now is around 50 Gwei (0.00000005 ETH). So a KB of storage costs 0.032 ETH. A GB costs 32,000 ETH.

To test this empirically, I created a contract with this code:

contract test {
    bytes data;

    function addData(bytes _data) public {
        data = _data;
    }

}

at address transaction.

Then I sent a transaction adding 1KB of data ("0x111111...." 2k times).

This transaction took 753,072 gas (0.03765 ETH at current prices).

It costs about 0.003 ETH to call the contract without adding any data, so that equates to about 0.035 ETH per KB ($0.076), or around $76,000 USD per GB of storage.

Retrieving this data is free, though.

15
  • "It costs about 0.003 ETH to call the contract without adding any data, so that equates to about 0.035 ETH per kb ($0.076), or around $76,000 USD per GB of storage." Does this mean it cost $0.076 per KB you want to add to the contract, so lets say i have a contract that holds 2 GB of data and i want to add 5 KB to it. does this mean it will cost me $0.38 or $375000.38 ??
    – 0xtuytuy
    Commented Dec 6, 2016 at 15:52
  • 1
    Right. But you probably don't actually need to store every hash on-chain. You could just store the root of a merkle tree. Commented Dec 6, 2016 at 16:02
  • 19
    What a difference 14 months make. Today (4/24/2017), 0.035 ETH costs $1.75 at the price of ~$50 per ETH. That puts the cost of 1GB of storage at $1,750,000, i.e. 1.75 million dollars, instead of the $76,000 that it was 14 months ago (in Feb 2016) Commented Apr 24, 2017 at 18:55
  • 6
    Today, with 1ETH = USD 311 (apron.), it would exceed USD 10 mil!!
    – user22929
    Commented Nov 14, 2017 at 15:30
  • 4
    Should be 233M$/GB as of right now with 200 Gwei average gas prices and 1823$/ETH Commented Mar 17, 2021 at 22:11
15

I wanted to give a quick update on this topic. (The other answers with prices are kinda outdated).

Same as the other answer a kilobyte of data is 640k gas.

But in contrast to two years ago the gas price in 2019 is ~10 gwei instead of 50 gwei.

However the price of ETH also increased.

Two years ago it would cost you $0.076/KB.

In August 2019 it costed you $1.204/KB.

As of 23.07.2020 the gas price spiked to 80 gwei so the storage now costs $13.82/KB!

1

Once stored how do you download the data back onto your desktop?

Every Ethereum transaction is publicly viewable. All you need is a viewer. Like this one for example.

enter image description here

How much would this cost exactly in ether/gas/fiat at todays prices?

It doesn't work like that.

You can fetch in real time, the current transaction pricing data here.

enter image description here

Your question implies a centralized pricing model. For example, in traditional centralized transactions (e.g., credit cards, wire transfers, ECH, etc.), the price is set by the payment processor. But the Ethereum network is decentralized. So it works in reverse fashion compared to the centralized model.

There is no single payment processor. Instead, there is a network of competing processors called "miners." Miners invest computing time and resources necessary to solve the math problem required to confirm and complete any given transaction.

Under this model, the sender sets the price with an offer to the network (miners). The Ethereum network responds to the price offered (which is a defacto incentive for the miners to solve the math problem necessary to hash a block) with a transaction. The time it takes to complete a transaction is correlated to the inverse of the price offered by the sender. i.e., The higher the price offered, the more priority that transaction will receive by the miners and, therefore, the less time the transaction will take to complete.

The above site tracks and reports the current transaction times at common given price points.

-1

It is expensive on Ethereum mainnet. However, on side chain (polygon, e.g.) or L2 (zkSync, Arbitrum/Optimism), the cost can be greatly reduced. Meanwhile, you can choose low gas fee hours. It's additional 80% discount.

1
  • It doesn't answer the question how much it costs.
    – Ismael
    Commented Nov 12, 2022 at 1:38

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.