`[contract creation code storage out of gas]` error when trying to deploy upgradeable contracts on Polygon

I am not able to deploy or upgrade any contract on Polygon anymore. Each time I try, I get the [contract creation code storage out of gas] error.

This an example of a tx that failed, while this is the same, on Mumbai, and succeeded.

:1234: Code to reproduce

A random simple contract:

//SPDX-License-Identifier: Unlicensed
pragma solidity ^0.8.4;

import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";

contract TestContract is OwnableUpgradeable, UUPSUpgradeable {
  /// @custom:oz-upgrades-unsafe-allow constructor
  constructor() {
    _disableInitializers();
  }

  function initialize() external virtual initializer {
    __Context_init_unchained();
    __Ownable_init_unchained();
  }

  function _authorizeUpgrade(address newImplementation) internal virtual override onlyOwner {}
}

A simple deploy script:

import { upgrades, ethers } from "hardhat";

async function main() {
  const Hook = await ethers.getContractFactory("TestContract");
  const hook = await upgrades.deployProxy(Hook, [], { kind: "uups" });
  await hook.deployed();
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

Console output:

InvalidDeployment [Error]: No contract at address 0x57C78E31d300152cbd5B91AB6b12f64D0464082f (Removed from manifest)
    at waitAndValidateDeployment (C:\Users\alvin\Development\Solidity\impact-self\node_modules\@openzeppelin\upgrades-core\src\deployment.ts:160:15)       
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async fetchOrDeployGeneric (C:\Users\alvin\Development\Solidity\impact-self\node_modules\@openzeppelin\upgrades-core\src\impl-store.ts:70:5)        
    at async deployImpl (C:\Users\alvin\Development\Solidity\impact-self\node_modules\@openzeppelin\hardhat-upgrades\src\utils\deploy-impl.ts:96:22)       
    at async deployProxyImpl (C:\Users\alvin\Development\Solidity\impact-self\node_modules\@openzeppelin\hardhat-upgrades\src\utils\deploy-impl.ts:74:10)  
    at async Proxy.deployProxy (C:\Users\alvin\Development\Solidity\impact-self\node_modules\@openzeppelin\hardhat-upgrades\src\deploy-proxy.ts:35:28)     
    at async main (C:\Users\alvin\Development\Solidity\impact-self\scripts\test-deploy.ts:6:16)

The tx hash for this contract deployment (check on PolygonScan, cannot link it due to new-user limits):
0x9c2ab3aa6e1a44c65938ad952cc791a02fe0d0aef1dbb2c8a02c08dbf5af7629

:computer: Environment

    "@chainlink/contracts": "^0.5.1",
    "@nomicfoundation/hardhat-network-helpers": "^1.0.8",
    "@nomiclabs/hardhat-ethers": "^2.2.2",
    "@nomiclabs/hardhat-etherscan": "^3.1.6",
    "@nomiclabs/hardhat-waffle": "^2.0.5",
    "@openzeppelin/contracts-upgradeable": "^4.8.1",
    "@openzeppelin/hardhat-upgrades": "^1.22.1",
    "@typechain/ethers-v5": "^10.2.0",
    "@typechain/hardhat": "^6.1.5",
    "@types/fs-extra": "^11.0.1",
    "@types/mocha": "^10.0.1",
    "chai": "^4.3.7",
    "dotenv": "^16.0.3",
    "ethereum-waffle": "^2.5.1",
    "ethers": "^5.7.2",
    "fs-extra": "^11.1.0",
    "hardhat": "^2.12.7",
    "hardhat-contract-sizer": "^2.8.0",
    "hardhat-deploy": "^0.11.23",
    "mocha": "^10.2.0",
    "solidity-coverage": "^0.7.22",
    "ts-node": "^10.9.1",
    "typechain": "^8.1.1",
    "typescript": "^4.9.5"

Can you try to manually set the gas limit? See this workaround to override the transaction options, but combine that with a custom gas limit according to this comment.

EDIT: There is now a txOverrides option where you can set the gas limit. See `[contract creation code storage out of gas]` error when trying to deploy upgradeable contracts on Polygon - #6 by ericglau

yes that seems to have fixed the issue. Thanks!

1 Like

I'm also having this error. how do i fix it? what code should i use? i'm still a beginner and i dont know how these things work. please help

so should i copy everything here and put it in my code?

There is now a txOverrides option, which overrides transaction parameters in Ethers v6.

For example:

  await upgrades.deployProxy(MyContract, ['My initializer arguments'], {
    txOverrides: { gasLimit: 1000000n },
  });