Smart Contract Maximum Size

I wonder if there is any limit on the maximum size of smart contract that can be deployed on Polygon?

1 Like

Yes there is.

2 Likes

thank you for sharing the link. In other words, Polygon has the same limits as Ethereum? We assumed Polygon removes Ethereum limits. Any additional info would be appreciated.

1 Like

very helpfull as we in process of launching on polygon Thx

To add to the earlier answer, as far as I know: on Ethereum the limit comes from EIP-170, which caps deployed runtime bytecode at 24,576 bytes (24 KiB). Polygon PoS is EVM-compatible, so I would expect the same cap to apply there, but I have not confirmed the value in the current Bor release. The quickest check is to deploy a test contract slightly above the limit on Amoy and see whether the deployment reverts. If a contract is too large, the usual options are to enable the optimizer and tune the runs setting, replace long revert strings with custom errors, move shared logic into external libraries, or split the system into several contracts behind a proxy or a diamond-style (EIP-2535) layout. The limit applies to the deployed code, so check the size report from your toolchain (for example hardhat-contract-sizer) after each change.