3

In my contract, there is a struct type:

struct Claim {
    address healthcareProvider;
    uint amount;
    bool patientSig;
    bool paid;
    uint item;
}

And the initialize function is:

function MakeClaim(uint _amount, uint _item, uint num) {
    Claim memory c;
    c.healthcareProvider = tx.origin;
    c.patientSig = false;
    c.paid = false;
    c.amount = _amount;
    c.item = _item;
}

When I call this function to create a new Claim type, I find the price is 2.687 ETH (not gas). This is much more than the cost for deploying the entire contract! I am testing it on the Morden test net. Where is my problem?

1
  • This function stores some arguments into memory, this is pretty cheap operation for the struct (tens of gas) comparing to storing data in storage (thousands of gas). Please measure operation/transaction costs in GAS, not in ETH. Maybe you gas price is too high?
    – k06a
    Commented Jan 12, 2023 at 13:19

1 Answer 1

1

As in blockchain data-store is a scarce resource, it's pretty expensive. Storing data is the most expensive operation in any smart contract.

sstore  100     Paid for a normal SSTORE operation (doubled or waived sometimes).

You can see the whole list: https://www.cryptocompare.com/coins/guides/what-is-the-gas-in-ethereum/

So, if you are using complex structures, the cost is multiplied.

4
  • So two bools, two unsigned ints, and an address cost over 30 USD every time you want to save or update them? Am I misunderstanding how Ethereum works? Commented Nov 4, 2016 at 13:22
  • 1
    30 USD seems to be so much even for that. Check the gas price and the estimated gas usage in solidity online compiler (ethereum.github.io/browser-solidity). Are you running this smart contract in live net or in a private testnet?
    – KanekiDev
    Commented Nov 7, 2016 at 7:13
  • What do you mean by complex structures? Do you have any example for a simple struct case? @KanekiDev
    – alper
    Commented Jun 1, 2017 at 9:48
  • A complex structure may be for example: if you want to build a tree-structure in your smart-contract.
    – KanekiDev
    Commented Jun 1, 2017 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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