You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署Solidity合约时遇到TypeError: simpleContract.deployed is not a function at main错误的问题求助

部署Solidity合约时遇到TypeError: simpleContract.deployed is not a function at main错误的问题求助

大家好,我最近在尝试部署一个简单的Solidity合约时碰到了报错,折腾半天没搞明白问题出在哪,想请教下各位大佬。

先给大家看看我的代码:

合约文件(contracts/SimpleContract.sol)

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract SimpleContract {
    string public message = "Hello, World!";
}

部署脚本(scripts/deploy.js)

const hre = require("hardhat");

async function main() {
  console.log("Deploying SimpleContract...");

  const SimpleContract = await hre.ethers.getContractFactory("SimpleContract");
  const simpleContract = await SimpleContract.deploy();

  console.log("Contract deployment transaction created, waiting for confirmation...");
  await simpleContract.deployed();

  console.log("SimpleContract deployed to:", simpleContract.address);
}

main().catch((error) => {
  console.error("Error during deployment:", error);
  process.exitCode = 1;
});

我先启动了本地Hardhat节点,然后执行了部署命令:

npx hardhat run scripts/deploy.js --network localhost

结果输出到一半就报错了,完整的错误信息如下:

Deploying SimpleContract...
Contract deployment transaction crea...
TypeError: simpleContract.deployed is not a function at main

我查了下Hardhat的文档,记得deploy()返回的合约实例应该有deployed()方法用来等待部署确认,怎么会提示这个方法不存在呢?有没有人能帮我分析下可能的原因,或者该怎么解决这个问题?

备注:内容来源于stack exchange,提问作者Jayakant Purushoth

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.15 11:04:32