I get the following error when deploying my contract in Remix:
Contract creation initialization returns data with length of more than 24576 bytes. The deployment will likely fails.
More info: eip-170
The contract is divided to 2 contracts. A with 250 lines and B (B is A) with 500 lines. I also created a library and exported some of my functions to this library. I am currently uploading to Javascript VM environment. Worth noting that when I make the Enable Optimization checkbox on the Compile tab valid, it still doesn't work. I have a couple of questions:
1) How can I check the size of the data in Remix? I get an error that it is over 24kb, how can I check how much is it exactly?
2) What is causing this? Is this related to the length of the code or the amount of gas that is executed? If it's the gas, how come when I add a lot more gas to the gas limit in the Run tab in remix it still gives me the same error.
3) Any common ways to decrease the size of the data so I could actually deploy it?
Thanks
Best Answer
The code size problem you reported means simply that your code compile in a too big low level program. Too much bytes in it.
Nothing related to gas or out of gas: simply it is bigger than permitted.
Usually this kind of problems arise with very long listings and/or in presence of very big static constant (arrays, tables, etc). In that a case you should have some separate sw units (as you apparently already did) and reduce the amount of storage required.
BUT it can be a problem related to remix IDE. Before to going on further, save your files, clear the browser cache and restart the browser. (BTW Chrome seems to have a better relationship with Remix than other browsers...)
On the other hand, if you are progressively developing your code adding new functions and testing them before to going on, simply try to have a back step deleting last function added and be sure that the error ceases to pop up. After that, simplify all you can.
If the error does not cease to pop up when deleting your last add, the overall design can be poor and too memory consuming by nature.
See How to estimate my contract code size? it is too big to deploy now also!
It is important to underline that splitting the contract in more than one contracts/libraries reduces the bytecode size if, and only if, they can be deployed separately and you do deploy them separately. Otherwise the resulting bytecode is bigger!
Check you public variables as well: may be that some of them can become ‘private’. In that a case the compiler does not create a getter for them (the net result of this intervention, for the sake of clarity, depends on a lot of other things... anyway try it).