Search code examples
solidityhardhat

(Warning: Contract code size exceeds 24576 bytes) Pops on Hardhat but not Remix


Remix compiles the code without the warning using their optimized but hardhat throws an error "(Warning: Contract code size exceeds 24576 bytes)"

Hardhat config:
module.exports = {
  solidity: "0.8.7",
  settings: {
    optimizer: {
      enabled: true,
      runs: 500,
      details: { yul: false },
    },
  }....

What could be an issue? How to tackle it?


Solution

  • you need to mention the optimization settings inside the version since hardhat execute

    multiple solidity version code.

    Example for single version settings

    module.exports = {
          solidity: {
            version: "0.8.9",
            settings: {
              optimizer: {
                enabled: true,
                runs: 1000,
              },
            },
          },
        };
    

    For multiple version support settings

    solidity: {
        compilers: [
          {
            version: "0.6.12",
          },
          {
            version: "0.5.16",
          },
          {
            version: "0.6.6",
            settings: {
              optimizer: {
                enabled: true,
                runs: 1000,
              },
            },
          },
        ],
      },
    };