I am using Hardhat and OpenZeppelin upgradeable contracts. So far, everything works correctly with deploying the V1 of the contract. However, when I'm upgrading to V2, the owner is set to address 0x0 for some reason. The expected behavior is that the owner of the contract should stay the same, since the upgrade is initiated by the owner.
./scripts/prepare_upgrade.js
const { ethers } = require("hardhat");
async function main() {
const [deployer] = await ethers.getSigners();
const myContractV1Address = "0x64291acc5af4B9DAF59C04412b987DEe9EA167E0";
const MyContractV2 = await ethers.getContractFactory("MyContractV2");
console.log("Deploying contracts with the account:", deployer.address);
console.log("Preparing V2 upgrade...");
const myContractV2Address = await upgrades.prepareUpgrade(
myContractV1Address,
MyContractV2
);
console.log("V2 address: ", myContractV2Address);
const myContractV2 = await MyContractV2.attach(myContractV2Address);
await myContractV2.setVersion("2");
// Checking for the same owner
const owner = await myContractV2.owner(); // this logs 0x0
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
What am I missing here?