Factory contract too large - should I use interface and a deployer contract?


I am looking for a suggestion on what is the best standard on optimizing a long contract.

I am checking / upgrading a long contract. It has a main contract and a factory contract that keeps multiple instances of the other contract.

The thing is the factory contract uses the other contract under same file and directly references the contract instead of an interface.

With some additions my truffle complains it complains about it's size:

Warning: Contract code size exceeds 24576 bytes (a limit introduced in Spurious Dragon). This contract may not be deployable on mainnet. Consider enabling the optimizer (with a low "runs" value!), turning off revert strings, or using libraries.

I went ahead and created an interface with all external functions available on the other contract and referenced it on the factory contract instead of the actual contract; and the complaining went ahead.

Also used a new deployer contract that simply deploys the contract and returns the address to the factory contract.

I just want to know if this is the correct way to go for?


Hi, welcome! :wave:

I think when you try to deploy contracts, you can enable Optimization in your config, and then have a try.

1 Like