2

I wrote a simple auction contract file and its size is 9.49KB(12KB on disk), and when I run this contract using npx hardhat test, I get this error:

Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (reason="Transaction reverted: trying to deploy a contract whose code is too large", method="estimateGas", transaction={"from":"0xf39Fd6e...

I think this error occurs when the contract files exceeds more than 24,576 bytes, which means 24KB. But my file exceeds only 10Kbs and I can't downsize my code anymore. What should I do?

1 Answers1

2

It might be summing with the size of your imports. Try using allowUnlimitedContractSize

sorold
  • 475
  • 7
  • 17
  • 1
    Be careful though, you may have the problem when you attempt to deploy to an actual network. One thing that will add a lot of size to a contract is any use of the 'new' function inside a contract function. It will bloat the size of the contract that calls new with the size of the contract that is created inside of it. You will not be able overcome the problem by ignoring it, which you can do in ahrdhat but not an a actual network. Also when you say the contract is 10K in size, do you mean the .sol file? That's not what is being measured. Its the size of the compiled bytecode. – GGizmos Aug 31 '22 at 05:26