1

Lets say, I want to create a smart contract that can receive a record of data per hours, e.g. hourly rates of ETH/EUR. These data would be stored in an array.

What would each transaction cost me and how can I estimate these costs?

marked as duplicate by Tjaden Hess Jun 23 '18 at 8:32

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.

3

By pushing a new element in the array, you are setting the storage value from zero to non-zero, therefore it has a cost of 20k gas, plus 5k to update the length member of the array, so it's a total of 25k gas.

So, if your function, say function add_data(uint256[] data) gets in parameter an array of length n, then your gas cost will have a lower bound of 25000*n.

You can find more informations in the yellow paper.

Edit : integrated Jesse's comment.

  • 2
    Pushing into a dynamic array will also incur 5000 gas cost to update the array length field. – Jesse Busman Jun 22 '18 at 20:45
  • Thank you! Will there be also a execution fee every time I call this method? – delete Jun 23 '18 at 16:53
  • What do you mean? The execution fee is the gas you will pay. – Eli Drion Jun 23 '18 at 17:11

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