Forceimport shows Error: The following deployment clashes with an existing one at and can not upgrade contract

I cannot upgrade my contract. first I used forceImport to generate json file. I deployed two same contracts before. But when I generate them. it shows 'Error: The following deployment clashes with an existing one at'.
If I ignore it. when I use upgrades.upgradeproxy to upgrade. The implements contract stays in very old one.
I upgrade one of them succeeded. But the other one always remains in very old one.

:1234: Code to reproduce

import { ethers, upgrades } from 'hardhat';
async function main() {
const signers = await ethers.getSigners();
const addr = await signers[0].getAddress();
console.log(`deployer address: ${addr}`);

const contract = await ethers.getContractFactory('MyContract');
const deployedProxyAddress = myAddress //eth mainnet
await upgrades.forceImport(deployedProxyAddress, contract)// if I annotated this line after it generated. It still cannot work.
const sbt = await upgrades.upgradeProxy(deployedProxyAddress, contract);

console.log(await upgrades.erc1967.getImplementationAddress(sbt.address), " getImplementationAddress")
console.log(await upgrades.erc1967.getAdminAddress(sbt.address), " getAdminAddress")


}

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

:computer: Environment


When you run forceImport, ensure you pass in the contract factory of the current implementation contract, not the one that you are upgrading to.

After it is imported, there is no need to run forceImport again.

Then you can run upgradeProxy with the contract factory of the NEW implementation that you are upgrading to.

If you still encounter the issue, please provide the information listed in Required information when requesting support for Upgrades Plugins

1 Like

Thanks, It worked. But I have a further question. If I miss my current implementation contract factory, how to upgrade my code? In this case forceImport will not work.

Can you clarify what you mean by "if I miss my current implementation contract factory"?