1

I want to create contract, which will be able to store data like array of:

struct Funder {
        address addr_first;
        address addr_second;
    }

How can I calculate gas fee for transactions which inserts additional Funder to my array ?

Should I pay more and gas for each insertion or I should always pay a fix gas price for all insertions to my storage ?

For example, if I have to pay 10 Gas for first insertion, how many gas should I pay when I'll have thousands of Funders and want to insert another one?

marked as duplicate by lungj, atomh33ls, Badr Bellaj Jul 19 '17 at 8:40

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.

2

The cost depends on the actual function that does the writing, as you pay for every computational step. If you had a simple storage variable of your struct and a function

Funder fdr;

function setFunder(address a1, address a2) {
  fdr.addr_first = a1;
  fdr.addr_second = a2;
}

then you can estimate the gas costs for every call via estimateGas as discussed here.

On lower level, the yellow paper tells us more on page 20: Writing one word (32 bytes for Ethereum) to storage (SSTORE opcode) costs you either 20'000 gas for an SSTORE operation when the storage value is set to non-zero from zero or 5'000 gas for an SSTORE operation when the storage value’s zeroness remains unchanged or is set to zero. I.e. the first time you call the function it will be more expensive than all following times that you reset it.

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