hardhat部署问题

1.首先创建了一个测试的合约如下:

`// SPDX-License-Identifier: MIT pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract cUSDT is ERC20 { constructor() ERC20("fake usdt in cbi", "cUSDT") { _mint(msg.sender, 1 * 10*8 10**18); //发行总量一个亿的币,精度18 } }`

2.写了部署脚本deploy.js文件如下:

const hre = require("hardhat");

async function main() { // Get the contract factory

const cUSDT = await hre.ethers.getContractFactory("cUSDT");

// Deploy the contract const cusdt = await cUSDT.deploy();

// Wait for the contract to be deployed await cusdt.deployed();

// Log the contract address console.log("cUSDT deployed to:", cusdt.address); }

main() .then(() => process.exit(0)) .catch((error) => { console.error(error); process.exit(1); });

如果添加 await cusdt.deployed(); 会报错Deployment failed: TypeError: cusdt.deployed is not a function,但是如果删除 await cusdt.deployed(); 则终端显示cUSDT contract deployed to: undefined,这是什么原因呢?

求助应该怎么样才可以部署成功???

package.json文件如下:

{ "name": "hardhat-project", "devDependencies": { "@nomicfoundation/hardhat-toolbox": "^5.0.0", "@openzeppelin/contracts": "^5.0.2", "ethers": "^5.0.0", "hardhat": "^2.22.7" } }

hardhat.config.js文件如下:

require("@nomicfoundation/hardhat-toolbox");

/* @type import('hardhat/config').HardhatUserConfig / module.exports = { defaultNetwork: "hardhat", networks: { hardhat: { chainId: 1337, accounts: { mnemonic: "test test test test test test test test test test junk junk", initialIndex: 0, count: 10, }, }, }, solidity: { version: "0.8.24", settings: { optimizer: { enabled: true, runs: 200, }, }, }, };

请先 登录 后评论

最佳答案 2024-09-11 17:24

兄弟,这个问题我碰到过,你应该是使用了nomicfoundation/hardhat-toolbox。 在这个工具中deployed()已经废弃了。 // Wait for the contract to be deployed await cusdt.deployed();

// Log the contract address console.log("cUSDT deployed to:", cusdt.address); 改成 // Wait for the contract to be deployed await cusdt.waitForDeployment();

// Log the contract address console.log("cUSDT deployed to:", cusdt.target);

请先 登录 后评论

其它 1 个回答

Alan
请先 登录 后评论
  • 2 关注
  • 0 收藏,620 浏览
  • Miraitowa 提出于 2024-09-09 13:42