1

I had a single contract that was exceeding the 24576 bytes, so after some reading on how to fight contract size, etc I have divided the contract into multiple contracts to import. Here below is the sample of my contract and imports.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "AccessControl.sol";   // Copy/paste OpenZepplin and saved on file
import "ERC20.sol";           // Copy/paste OpenZepplin and saved on file
import "KatoSublime.sol";     // Small file approx 30 lines,not many struct/string 
import "KatoSublimeBuy.sol";  // Small file approx 30 lines,not many struct/string 
import "KatoSublimeFees.sol"; // Small file approx 30 lines,not many struct/string 

contract Kato is ERC20, AccessControl, KatoSublime, KatoSublimeBuy, KatoSublimeFees {
// Code here!
}
  • Although I have now divided the contract, it still gives me the error.
  • Not only that, but before when the contract was all in one, I just needed to cancel a line like an event/emit/string to get rid of the error, now it does not.
  • When I cancel lines from the other contracts imported the error goes away.

What am I doing wrong and how to fix it?

  • Shell I import the file differently with the @..... or ../ or shell I just put them in the same file but in separate contracts?

I would like to be able to create many small contract with related functions and not worry about this issue anymore.

How can I fix this?

0

1 Answer 1

1

It is true that the contract size limit has been crossed because you are importing so many external contracts into it. However, simply breaking the whole contract into smaller parts but still importing the newly created contracts into your original contracts doesn't save much space for your original contract's size (if any).

The way to solve this is import only the interfaces of the other contracts instead of the whole contracts.

Not the answer you're looking for? Browse other questions tagged or ask your own question.