Check the 24 KB contract size limit
Ethereum rejects contracts whose deployed code is larger than 24,576 bytes, a rule introduced by EIP-170, and since EIP-3860 it also rejects creation code over 49,152 bytes. Paste the compiled bytecode from Hardhat, Foundry, Remix or solc and this tool tells you how close you are, how many bytes you have to spare, and a floor estimate for the gas needed to deploy it.
Runtime versus creation bytecode
- Runtime (deployed) bytecode is what stays on the chain. It is the one the 24 KB limit applies to. In Hardhat it is the deployedBytecode field, and in Foundry it is the deployedBytecode in the artifact.
- Creation (init) bytecode is runtime code plus the constructor and is what the deployment transaction carries. It is checked against the 49,152 byte initcode limit.
How the gas estimate works
A deployment pays 21,000 base gas, 32,000 for contract creation, and calldata gas of 4 per zero byte and 16 per non-zero byte. Contracts then pay 200 gas for every byte of runtime code stored, and EIP-3860 adds 2 gas per 32-byte word of initcode. The estimate cannot include what your constructor does when it runs, such as writing storage or calling other contracts, so treat it as the minimum and measure the real cost on a test network.
Ways to shrink a large contract
Enable the optimizer with a low runs value, use custom errors in place of revert strings, remove unused code, move shared logic into libraries, and split big systems across several contracts. Other chains and test networks can have different limits, and some allow larger contracts, so check the one you deploy to. Foundry and Hardhat can also print contract sizes during a build.
The 24 KB limit
Ethereum limits deployed contract code to 24,576 bytes under EIP-170. If the compiled runtime bytecode is larger, deployment fails. Make sure you check runtime bytecode, not creation bytecode.
Reducing size
Enable the optimizer with a suitable number of runs, move code into libraries, remove unused functions, use custom errors instead of long revert strings and split a contract into several using proxies or the diamond pattern.
Gas considerations
Deployment cost grows with bytecode size, so smaller contracts are cheaper to deploy, though over-optimising for size can raise runtime gas. Measure both with your test suite.
Deploy checks
Use the compiler's size report or a Hardhat or Foundry plugin to track bytecode size on every build. Check runtime size with the optimizer on, because it often lowers size. If you are close to the limit, plan to split logic across contracts early, since refactoring later is harder. Test deployment on a local node and a testnet before mainnet, and review audits for each upgrade.
Testing and tooling
Add a size check to continuous integration so a build fails when a contract nears the limit. Foundry and Hardhat both have options to print contract sizes. Review compiler version and optimizer runs, because they change size and gas. Keep a record of results for each release.