0

我正在使用 Hardhat 和 OpenZeppelin 可升级合同。到目前为止,部署合约 V1 时一切正常。但是,当我升级到 V2 时,出于某种原因,所有者设置为地址 0x0。预期的行为是合约的所有者应该保持不变,因为升级是由所有者发起的。

./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);
  });

我在这里想念什么?

4

0 回答 0