New to blockchain software development? Read my beginners guide here

Max contract size on Ethereum

Created on August 2022 • Tags: ethereumsolidityguides

A guide about the maximum contract size on Ethereum


Table of Contents for Max contract size on Ethereum


“Spurious Dragon” was the 4th hard fork, at block num 2,675,000, back in 2016. It introduced a new contract code size limit of 24576 bytes.

You can see more about this at https://github.com/ethereum/EIPs/blob/master/EIPS/eip-170.md

If block.number >= FORK_BLKNUM, then if contract creation initialization returns data with length of more than MAX_CODE_SIZE bytes, contract creation fails with an out of gas error.

You may have seen the following error, telling you about this:

Warning: Contract code size 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.

How to reduce Solidity contract sizes

This is a list of ways to reduce your Soldiity smart contract code size.

  • remove unused code/functions
  • avoid creating variables (inlining variables can reduce size)
  • create smaller error messages
  • separate your contracts into their own contracts
  • try changing the optimizer settings
  • use proxies, use delegatecall
  • use libraries

Spotted a typo or have a suggestion to make this crypto dev article better? Please let me know!

See all posts (70+ more)

See all posts (70+ more)

Was this post helpful? 📧

If you liked this content and want to receive emails about future posts like this, enter your email. I'll never spam you.

Or follow me on @CryptoGuide_Dev on twitter

By using this site, you agree that you have read and understand its Privacy Policy and Terms of Use.
Use any information on this site at your own risk, I take no responsibility for the accuracy of safety of the information on this site.