"Deployment at address is not registered" when upgrading contract to new implementation

Hey OpenZeppelin Forum,

I have some random quirks which have occurred lately when we would like to do an upgrade through HardHat. We think it's the safest and easier way to upgrade a contract rather than doing it manually through Defender (advise me if that's incorrect).

It seems like hardhat has an issue with the new implementation and won't allow the new implementation to get created, and instead upgrade our contract to the current implementation.. hence nothing happened other than paying gas.

We think it has something to do with caching or something of that sort, but we are not sure as all the measures we tried so far haven't solved the problem for us. So we thought raising the issue would save us some time doing it ourselves.

We obviously made sure also to delete following folders before running our script:
.openzeppelin / artifacts and cache

:1234: Code to reproduce

The error we get looks like the following:

throw new UpgradesError(
          ^
UpgradesError: Deployment at address 0xaCf5Fc50f46019B685AFA2ea0a2ba4437188e9d0 is not registered

To register a previously deployed proxy for upgrading, use the forceImport function.
    at getStorageLayoutForAddress (/home/user/WORK/folderName/project/node_modules/@openzeppelin/upgrades-core/src/manifest-storage-layout.ts:20:11)
    at async deployImpl (/home/user/WORK/folderName/project/node_modules/@openzeppelin/hardhat-upgrades/src/utils/deploy-impl.ts:111:27)
    at async Proxy.upgradeProxy (/home/user/WORK/folderName/project/node_modules/@openzeppelin/hardhat-upgrades/src/upgrade-proxy.ts:25:32)
    at async /home/user/WORK/folderName/project/scripts/upgrade_auto.ts:89:19
node:child_process:902
    throw err;

:computer: Part of the script doing the deployment

const addresses = JSON.parse(data from file);
const ContractFactory = await ethers.getContractFactory(CONTRACT_NAME);
   var options: IOptions = {
      unsafeAllowRenames: false,
      unsafeSkipStorageCheck: false,
      kind: 'uups'
    };
var token = await upgrades.upgradeProxy(addresses.proxyAddress, ContractFactory, options);

:computer: Environment

Our environment is HardHat, we use the compiler version v0.8.15

Thank you in advance.

Do not delete the .openzeppelin folder, since that contains network files with information about your existing deployments. Network files for mainnet or testnet should be checked in to source control. See https://docs.openzeppelin.com/upgrades-plugins/1.x/network-files. If you have backups, restore them.

If you no longer have the .openzeppelin folder and cannot restore it, you would need to run the forceImport command to import your previously deployed proxies. For its deployedImpl parameter, make sure to pass in the ethers ContractFactory corresponding to the source code of the CURRENT implementation contract that your proxy is using. After you do the import, then you can proceed to upgrade it.


In terms of upgrading and Defender, you can use defender.proposeUpgrade which will validate and deploy the new implementation, and automatically creates an upgrade proposal in Defender for you.

1 Like

Thank you for swiftly replying, I will try suggested changes and get back to update if it solved my problem.

Thank you.

This worked perfectly.

Thank you @ericglau

1 Like