Code size to deposit exceeds maximum code size

Warning: Contract code size is 25790 bytes and 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.
Contract Falcon.

Dear all, I'm attaching the contract here as well,

I have tried optimization on remix, but it couldn't br deployed.

Then i tried on truffle and it's giving this above-mentioned error.

Needs your kind support please.

P.s this code smart Contract is not written by me, neither I'm confident Enough to optimise it myself as my dev skills are not so good.

Looking forward for your kind support, please

Smart contracts is


In contract Falcon, change all public and public payable functions to internal, as none of them seems to need more than that.

That alone solves the problem in this contract.

In contract FalconWrap, change the public function to external, as it doesn't seem to need more than that.

That doesn't solve the problem in this contract, but you may as well do it.

Then go to your hardhat configuration file, and change this:

  solidity: {
    version: "0.7.6"

To this:

  solidity: {
    version: "0.7.6",
    settings: {
      optimizer: {
          enabled: true,
          runs: 0

Strange are the ways of the Solidity optimizer...

BTW, if you do need those functions declared public for some reason, then the second step mentioned above (enabled: true) alone solves the problem on the Falcon contract.

But you'll still need to figure out a way to solve the problem on the FlaconWrap contract.

For example, you can split the Falcon contract into two contracts:

  1. Move all pure and view functions from the Falcon contract into a new contract
  2. Declare some of them as public and some of them as external, as needed
  3. Move all storage variables from the Falcon contract into the new contract
  4. Add functions to make some of them accessible to the Falcon contract, as needed
  5. Restrict permission on some of these functions to the Falcon contract only, as needed

That should help reducing the size of the Falcon contract, and since the FalconWrap contract inherits from the Falcon contract, that should also help reducing the size of the FalconWrap contract.