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?
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.Sign up to join this community
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
You can find more informations in the yellow paper.
Edit : integrated Jesse's comment.