Understanding data storage

I'm trying to understand how Ethereum stores data that I send, if I have a transaction that sends 20 bytes of data to a contract then before the contract has even been executed the blockchain has access to my sender account, the 20 bytes of data and my tx signature.

Does this get stored in the blockchain? Can I access it via an API?

Or do I need to make sure my contract uses storage to save the 20 bytes because its not saved in the blockchain?

I would have thought the blockchain needs to store the full tx including 20 bytes so that other nodes can replicate it.


  • FlanaganFlanagan Member Posts: 15
    Or lets say I have a contract that does nothing just returns straight away, so the fee should be 0 or minimum.

    But lets say I send a tx to my contract which includes 100 bytes of data.. what is the fee I pay for this tx? are my 100 bytes stored on the blockchain?
  • TalkingAntColonyTalkingAntColony Member Posts: 9
    All transactions are stored in the blockchain, just like Bitcoin. Regarding storage fees, you pay both for the size of the Tx in bytes and for the size of the new data put into contract storage. If you remove data from contract storage (I.E. after your tx executes, the total contract storage is smaller), you get a refund up to half the gascost of the tx (you cant get sent ether back, but your tx fee can be subsidized).

    The moment you send your tx, all nodes will know about it. After the next block it will be "in" the blockchain. Ethereum clients maintain a state database of all contracts, which is analogous to Bitcoin's UTXO set. Typically you will query this state database rather than finding all transactions for a given contract and simulating the state history yourself. But you can access both contract storage and blockchain data with the RPC interface:

  • FlanaganFlanagan Member Posts: 15
    edited April 2015
    Thanks TalkingAntColony, I already have an app that basically just uses another blockchain for tx ordering and I maintain state within my app. I'm just trying to figure out how hard it would be to recreate it on Ethereum, with the eventual goal to start utilising ethereum for managing some parts of the state. It sounds like it would be pretty easy.

    Do you have any links for more info regarding tx submission fees? Particularly the fee per byte.

  • TalkingAntColonyTalkingAntColony Member Posts: 9
    I believe it's 5 gas per byte. For computation costs, check here:


    Also the yellow paper might be useful.
  • StephanTualStephanTual London, EnglandMember, Moderator Posts: 1,282 mod
    Yellow paper (http://gavwood.com/paper.pdf) Appendix G is indeed what you're looking for.
  • oliverkxoliverkx Member Posts: 85
    Just to make sure I understand this correctly, if for example I sent 100 bytes of data to a contract, and the contract doesn't do anything with that data, doesn't store it, etc. Are those 100 bytes still stored in the block-chain as transaction history? And what would be the cost of storing those bytes in this way (block-chain/transaction history only) as opposed to storing them in the actual contract (state-tree)?

    And from a usage point of view, I imagine that the transaction history would be a lot slower to traverse, compared to retrieving the data from the contract? Does Ethereum provide a function for searching through the transaction history, or would I need to "hack" into the block-chain using some other means?

  • FlanaganFlanagan Member Posts: 15
    You would pay the gas (i.e Ether) for the bytes in the tx. So more data, more gas. If you wanted to save that data into the contract storage then you would pay more gas. Seems like a waste. I would only save "state" data into contract.

    I have just released a DApp that uses events and the event filters to easily retrieve data sent in a tx. No state is stored in contract. Seems to work ok.
  • oliverkxoliverkx Member Posts: 85
    Hi Flanagan,

    thank you for the response! Could you by any chance point me to your DApp, or its source code?
  • racer8racer8 Member Posts: 9
    I don't understand the Ethereum blockchain very well so I have a basic question. If there are eventually millions of DApps each with code, transactions and data. This could be petabytes of data or more. Does the client have to store all of this?
  • buck8ochicknbuck8ochickn Member Posts: 1
    Flanagan are you talking about something like hashing some data and then storing that hash on the block chain for transparent verification.
  • FlanaganFlanagan Member Posts: 15
    Hey buck8ochickn, in the Airlock DApp I linked to above it is basically as you say, taking a hash of the data and the contract is raising an event with that hash when receiving a tx.

    Then my DApp can just subscribe to the event feed and get a list of hashes. Works pretty well, no need to save any contract state.

    In my original post from April I was thinking I might need to traverse each block in the blockchain looking for txs and extract the data/hash.. but thankfully ethereum events make this easy.
Sign In or Register to comment.