EVMTools

Contract Size Calculator

Check if your Solidity contract bytecode fits within the 24KB EIP-170 limit. Paste bytecode to see size, percentage used, and optimization tips.

What is EIP-170?

  • EIP-170 introduced a maximum deployed contract size of 24,576 bytes (24 KB) as part of the Spurious Dragon hard fork (Nov 2016).
  • This limit prevents denial-of-service attacks through excessively large contracts that would slow down the network.
  • The limit applies to the deployed bytecode (runtime code), not the creation/constructor bytecode.
  • EIP-3860 (Shanghai upgrade) also limits initcode to 49,152 bytes (2x the runtime limit).

Tips for Reducing Contract Size

  • Use libraries: Extract shared logic into external libraries to reduce duplicated bytecode.
  • Split contracts: Use the proxy pattern or diamond pattern (EIP-2535) to split logic across multiple contracts.
  • Shorter error messages: Replace long require/revert strings with custom errors (saves significant bytes).
  • Optimizer: Enable the Solidity optimizer with a low "runs" value (e.g., 200) to optimize for deployment size.
  • Remove unused code: Remove dead functions, unused imports, and debugging utilities before deployment.
  • Use via-IR: The Solidity via-IR pipeline can sometimes produce smaller bytecode.

How to Use This Contract Size Calculator

This tool measures your smart contract's bytecode size and checks whether it fits within the EIP-170 deployment limit. It helps you identify size issues before deploying to mainnet.

  1. Get your contract bytecode — compile your contract with Hardhat, Foundry, or Remix and copy the deployed (runtime) bytecode hex string.
  2. Paste the bytecode into the input field. The tool accepts hex strings with or without the "0x" prefix.
  3. View the size analysis — the tool shows the bytecode size in bytes, the percentage of the 24KB limit used, and a clear pass/fail indicator.
  4. Optimize if needed — if your contract is close to or exceeds the limit, follow the optimization suggestions to reduce the bytecode size.

All calculations run locally in your browser. Your bytecode is never sent to any server.

Common Use Cases

  • Pre-deployment check — Verify that your contract bytecode fits within the 24KB limit before spending gas on a mainnet deployment.
  • Optimizer tuning — Compare bytecode sizes across different Solidity optimizer settings to find the best runs value for your contract.
  • CI/CD integration — Quickly check contract sizes during code review to catch size regressions before merging.
  • Contract splitting decisions — Determine when a contract needs to be split into multiple contracts or use a diamond/proxy pattern.
  • Gas cost estimation — Larger bytecode means higher deployment gas costs. Use this tool to estimate deployment costs based on bytecode size.

Related Tools

Frequently Asked Questions

What is the maximum smart contract size on Ethereum?

The maximum deployed contract bytecode size is 24,576 bytes (24KB), introduced by EIP-170 in the Spurious Dragon hard fork. This limit prevents excessively large contracts from degrading network performance. If your contract exceeds this limit, the deployment transaction will fail.

What is the difference between init code and deployed bytecode?

Init code (creation bytecode) is the code that runs during contract deployment, including the constructor logic. It returns the runtime bytecode that is stored on-chain. The EIP-170 limit applies to the deployed (runtime) bytecode, not the init code. However, EIP-3860 introduced a separate 49,152-byte limit for init code.

How can I reduce my contract size?

Common strategies include: enabling the Solidity optimizer with a low runs value (e.g., 200), using libraries for shared logic, splitting into multiple contracts with a proxy pattern, removing unused functions, using shorter error messages or custom errors, and minimizing the use of public variables (which generate getter functions).

Does the optimizer always reduce contract size?

Not always. The Solidity optimizer's 'runs' parameter trades off between deployment cost (smaller bytecode) and runtime cost (cheaper execution). A low runs value (1-200) optimizes for smaller size, while a high value (10000+) optimizes for cheaper execution at the cost of larger bytecode. For size-constrained contracts, use a low runs value.

What is the EIP-3860 init code size limit?

EIP-3860 (Shanghai upgrade) introduced a maximum init code size of 49,152 bytes (2x the runtime limit). It also adds a gas cost of 2 gas per word of init code. This prevents extremely large constructor logic from consuming excessive resources during deployment.