Out of the contracts that you are using from openzeppelin-solidity, ERC777 is the largest in terms of bytecode size, but it isn't part of openzeppelin-eth currently.
I created a Sample contract to import your dependencies to get their sizes.
Could you share some more details about your project? Often large contracts can be broken down into smaller parts that can call into each other, but that’s on a very case-by-case basis.
Hey @abcoathup! I tried calculating sizes with the method described in the ganache issue but they not match up with the sizes I was looking at. Usually I’m taking the deployedBytecode value of the main contract and put into a new file (eg bytecode.hex), then making ls -l bytecode.hex which currently gives me 45417.
With the other method I got 22709.5 which seems fine but when I try to deploy I got the out-of-gas error.
@abcoathup@nventuro here are the contracts https://github.com/bugduino/idle/tree/master/contracts (they are still a WIP and a bit raw, tests should be implemented as soon as I’m able to get the size down to 24K).
The main one is IdleDAI. The IdleHelp is the library I made so far. I’m still not very familiar with writing libraries, for example how can I move the claimITokens method (which calls the rebalance method of the main contract) in the library?
Not sure about this but worth checking: have you tried without the optimizer? I think it optimizes for gas usage so not necessarily for contract size, though maybe the runs: 1 parameter does bias the compiler to optimize for size.
I tried without the optimizer but got the same result. I have like 4 small tests for the contstructor which are passing.
Isn’t ls -l or ls -lh already returning the size in KB?
If i may suggest, i have run into this issue before myself. One solution that I like, and plays nice with ZeppelinOS is to group each piece of functionality of the contract together and then deploy this chunk of associated code as an EVM package. This gives the added benefit of being able to optionally upgrade the logic of different parts of your application separately.
This way you can avoid the contract size problem all together, create small, easily testable, isolated segments of code functionality. The end result is easier to test, easier to reason about and easier to fix if a problem occurs. It is my preferred solution to contract size limits.
Anyway I find out that even if I remove all the code from the main contract except for the constructor it still fails to deploy unfortunately. If I replace the ERC777 constructor with the ERC20Detailed one it works properly.
I’ve had issue with this limit as well with my current project. You definitely want the compiler optimization on. If you toggle optimization on and off the code size will change (if it doesn’t you should look elsewhere for the issue). Breaking up the contract has not worked for me in the past, as inherited code gets injected in the contract to be deployed. Using an EVM seems like a solution, or deploying multiple contracts that call each other. My issue was that I was compiling without optimization, when I engaged it I was able to deploy a contract with a lot of code in it. So unless your contract is very large, which it doesn’t seem likely from the imports listed above, there may be another issue.
Have you put the contract in Remix and played with different complier versions?