I am working with truffle and solidity (v0.4.23) and found out that when I pass in an argument of constructor some bigger amount of data (16kB) that are saved to storage of a smart contract, it is substantially more expensive than storing the same data just after the deployment of contract through an argument of a method.

In detail of my example, the cost of storing data during the deployment is 23M of gas, while storing it by a method of contract consumes only 8.5M. I know that this is out of mainnet's limit (8M), but I am very curious why this happens. Note that this happens even when I stay under the gas limit, but not so significantly.

  • 1
    Are you passing this data to the contract via the method/constructor arguments, or is the data generated dynamically? More generally how are you storing this data? When I try this experiment I get almost identical gas costs. – Tjaden Hess Oct 30 '18 at 15:47
  • It is passed through an argument (bytes16[] XY), both in the constructor case as well as in the method I mention. Data are stored as a storage variable: bytes16[]. – Ivan Homoliak Oct 31 '18 at 2:32
  • I'd suggest to check memory use, the gas cost for memory has a cuadratic behavior. – Ismael Nov 1 '18 at 19:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.