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;

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?


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.

  • 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? Nov 4 '16 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
    Nov 7 '16 at 7:13
  • What do you mean by complex structures? Do you have any example for a simple struct case? @KanekiDev
    – alper
    Jun 1 '17 at 9:48
  • A complex structure may be for example: if you want to build a tree-structure in your smart-contract.
    – KanekiDev
    Jun 1 '17 at 11:05

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.