0

Is there a way to pre-define a contracts storage when deploying it?

Say I want a mapping to be filled with 1000 entries but want to avoid having to pay gas for adding every entry on its own.

Since storage is just a key-value map, I was wondering if can't just hardcode its initial state.

2 Answers 2

0

A contract storage can be modified in two cases:

  • At contract deployment
  • A function is called during a transaction
0

You can add the 1000 entries during deployment by modifying the constructor. But you will still have to pay for the gas consumed.

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.