I have to implement a smart contract using large constants (about 30kb).

I read that there is a limit of 24kb on Solidity's contract size.

So I'm wondering if there is a nice way of circumventing this, because I know I can write a function that stores those constants and call it right after the contract's deployment.

Is there a better way of doing this?

  • Hmm, the 24Kb limit on Contract size should refer to the size of its code. Not the storage size of its variables. Did you maybe try to test this on your local network? (Did your contract deployment actually fail?)
    – Sky
    Nov 18, 2022 at 11:44
  • Not yet. There will be a major difference in the work I have to do depending on the answer to this question, so I'm trying to find out if there is a definite answer beforehand.
    – kuco 23
    Nov 18, 2022 at 11:49

1 Answer 1


Ok, so in short, 2^261 bytes is the theoretical limit on how much data you can store in smartContract. So there is no way you will ever fill that up.

However, the max size of the SmartContract (its code) is only up to 24Kb (on most EVM networks). Therefore your large constants 30Kb should not be an issue from that perspective. Because they don't increase the size of the code only storage.

For example: These two arrays have very different storage sizes (10 << 1000), but their code size difference is negligible.

unit[10] smallArray;

unit[1000] bigArray;

But what might be an issue for you is the blockGasLimit (The maximum amount of data/gas you can write/spend for a single block).

So if your transaction goes over the blockchain's blockGasLimit you will not be able to deploy the contract. Considering contract deployment is also just a big transaction.

In short. I don't believe large contact variables will be an issue. Rather it will be the size of the transaction that might limit you. And that is why you will need to test it locally first.

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.