1

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

  • for part 1) Check the byte code object of your contract, it should not exceed 24kb, lines does not directly mean bigger byte code as mentioned in @rick 's answer . – sp4c3 Jan 24 at 8:29
  • Ok did that. The weird thing is that as I said I have contracts A and B and B is A. When I remove the dependency of B from A and deploy A everything works and the contract is deployed. When I copy the bytecode and paste it in a txt file, the size is 60kb. I am confused as this error says it can't be bigger than 24kb? Worth mentioning that when B is A the bytecode size is 202kb :/ – Contentop Jan 24 at 8:38
  • github.com/ethereum/EIPs/blob/master/EIPS/eip-170.md "if contract creation initialization returns data with length of more than 0x6000 (2^14 + 2^13) bytes, contract creation fails with an out of gas error." So check your contract code after it is deployed, as it does not have intialization code ( constructor and all). It should probably be less than 24kb ( 14952 characters) – sp4c3 Jan 24 at 8:48
  • Any idea how to do so in Remix? before uploading you can check the bytecode on the Compile tab. After deployment where you can see the instance of the contract I am can't see where to check the bytecode of it (Reminding that I am not using some sort of testnet like Rinksby where you can use Etherscan, just Remix's Javascript VM). – Contentop Jan 24 at 9:00
  • In remix, go to details tab, look for 'runtime bytecode's object', if you have access using web3, then use web3.et.getCode(contractAddress) – sp4c3 Jan 24 at 9:06
0

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).

  • Thanks Rick, very helpful. Would you mind looking at my comment to @sp4c3 and clearing this up as well? – Contentop Jan 24 at 8:39
  • I added a link very useful: try to read that! – Rick Park Jan 24 at 9:09
  • "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!" How can I handle that? that means I should deploy the library, get the address and than reference it in a my contract? If so, is it possible to simulate it in Remix? thanks – Contentop Jan 24 at 11:25
  • I think it could be better for you to open one or some new questions on the matter and to try to have fully contributions from all the community. Anyhow think something like to split your contract by moving functions to a secon contract, and to calling them like in “otherContract.transfer(from, to, value);” or similar. Explaining this can be difficult in a comment, but multicontract approach is widely known. – Rick Park Jan 24 at 15:18
0

Enable optimization for smart contracts in remix.It will suceed

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.