What is the cheapest way for storing string in contract? I'm looking at this transaction https://etherscan.io/tx/0xb92d030c914254473b41af12309c6ccfaf8fe7388b0d0d8a0ac53545df3f773e and wonder that it used only 25851 gas. I have tried other datatypes like bytes, string and can't get same value.

  • How do you actually know what this contract/transaction are doing? There is no code attached?
    – ivicaa
    Apr 13, 2018 at 18:59
  • You can convert to ascii, and you'll see that, they are storing ipfs hash
    – user25688
    Apr 13, 2018 at 19:36
  • A hash will be typically bytes32. You can store it as raw binary data, there is no need to store its hex representation as a string. However, without the code you can not easily see what's actually happening. 25851 gas usage doesn't look like something is stored to contract's storage at all (or gas refund is triggering). Without gas refund, the smallest gas cost would be 21000 (base tx cost) + 5000 (update existing storage slot).
    – ivicaa
    Apr 13, 2018 at 19:45
  • From the vmtrace it doesn't use storage, but it uses logs instead. But without the source is impossible to say what it does with it.
    – Ismael
    Apr 14, 2018 at 18:56

1 Answer 1


If you need the contract to 'have access' to the variable, you will not manage a gas usage like the tx you included in your answer. However, if you need only a reference-type storage that will not have to be used from within the contract, use logs, they are much cheaper. As far as the transaction is concerned, just because a string is provided as input, doesn't mean it's stored inside the contract anywhere. In this case, it definitely isn't, as minimum storage cost is 5000 gas (+21k base tx cost = 26k).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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