Hardhat多次部署合约返回相同地址,调用会返回合约不存在

盘古给你一斧 盘古给你一斧 提出于 2022-11-23 20:19 3910 浏览

部署合约脚本结果: image.png 脚本如下:

const hre = require("hardhat");

async function main() {
  const currentTimestampInSeconds = Math.round(Date.now() / 1000);
  const ONE_YEAR_IN_SECS = 365 * 24 * 60 * 60;
  const unlockTime = currentTimestampInSeconds + ONE_YEAR_IN_SECS;

  const lockedAmount = hre.ethers.utils.parseEther("10");

  const Lock = await hre.ethers.getContractFactory("MyContract");
  const lock = await Lock.deploy(unlockTime, { value: lockedAmount });

  await lock.deployed();

  console.log(
    `Lock with 1 ETH and unlock timestamp ${unlockTime} deployed to ${lock.address}`
  );
}

// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

前端调用结果:

image.png

提示合约不存在???

最佳答案

2022-11-23 21:22

不指定网络,是一个 mock 环境,脚本运行完了也就没了, 如果是起了一个本地 devnet .需要指定一下这个本地网络

Jeack

采纳率 17% · 回答于 2022-11-23 20:25

其它 1 个回答

写回答

你需要登录后才可以回答问题,登录