Hello guys,
I have a question about creating a contract via a Factory contract, currently I'm facing a problem of code size like below :

import "./DAF.sol";
contract Factory {
function createDAF(DAFLib.NewDAF memory params) public {
DAF daf = new DAF(params); // this line of code cause the contract size to go from 2kb to 26kb ..
}
}

This really simple contract exceeds the code size limit :

Factory = 26.431 kb
Warning: Contract code size exceeds 24576 bytes


I'm stuck on it for multiples days, since I've not found any similar case :x
Any help would be really appreciated ! Thanks

Nov 3, 2021, 7:35 PM
Are you trying to get it to just compile or you really care about the size of the contract?
Nov 3, 2021, 8:28 PM
Just trying to compile
Nov 3, 2021, 8:29 PM
Are you using hardhat? Enabling optimization? If so, try with fewer runs.

Check out this article could help you identify why the compiler is telling you the contract is too large.

https://soliditydeveloper.com/max-contract-size
Nov 3, 2021, 8:37 PM
I'm using hardhat, and the plugin contact-sizer
I've already applied all advise on that link but thanks
Nov 3, 2021, 8:40 PM
do you have optimization enabled in hardhat config?

https://hardhat.org/guides/compile-contracts.html#configuring-the-compiler
Nov 3, 2021, 8:40 PM
Just this line of code cause 20Kb of bytecode, this is strange

DAF daf = new DAF(params);
Yes
Nov 3, 2021, 8:41 PM
okay try lowering the number of runs
Nov 3, 2021, 8:41 PM
optimizer: {
enabled: true,
runs: 500, /// https://docs.soliditylang.org/en/v0.8.9/internals/optimizer.html#optimizer-parameter-runs
},

I've tried already but for you I retry haha
Nov 3, 2021, 8:41 PM
hahah, try 50, or 200
Nov 3, 2021, 8:41 PM
200 is enough
Nov 3, 2021, 8:42 PM
Same problem
```
contract Factory {
function createDAF(DAFLib.NewDAF memory params) public {
DAF daf = new DAF(params); // + 26kb of that line of code
}
}
```
And DAF contract size is 15kb
Nov 3, 2021, 8:43 PM
apart that, if your aim is to deploy always contracts starting from same base, I suggest to check proxy pattern
using Clones
Nov 3, 2021, 8:44 PM
Using this pattern ? https://solidity-by-example.org/app/minimal-proxy/
* Minimal proxy pattern
Not sure it will solve the initial problem of code size, but I'll check, thanks
Nov 3, 2021, 8:48 PM
also be sure that you approve the router
Nov 3, 2021, 9:46 PM

© 2024 Draquery.com All rights reserved.