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

为何无法部署智能合约?Sepolia测试网部署报错求助

部署Sepolia测试网时ethers v6 deployed()报错的解决方案

执行部署命令 npx hardhat run scripts/deploy.js --network sepolia 后,Solidity编译成功,但触发如下报错:

TypeError: no matching function (argument="key", value="deployed", code=INVALID_ARGUMENT, version=6.6.7)
    at makeError (C:\Users\Web3_Proj1\smart_contract\node_modules\ethers\src.ts\utils\errors.ts:670:21)
    at assert (C:\Users\Web3_Proj1\smart_contract\node_modules\ethers\src.ts\utils\errors.ts:694:25)
    at assertArgument (C:\Users\Web3_Proj1\smart_contract\node_modules\ethers\src.ts\utils\errors.ts:706:5)
    at Interface.getFunctionName (C:\Users\Web3_Proj1\smart_contract\node_modules\ethers\src.ts\abi\interface.ts:542:23)
    at buildWrappedMethod (C:\Users\Web3_Proj1\smart_contract\node_modules\ethers\src.ts\contract\contract.ts:342:34)
    at BaseContract.getFunction (C:\Users\Web3_Proj1\smart_contract\node_modules\ethers\src.ts\contract\contract.ts:870:22)
    at Object.get (C:\Users\Web3_Proj1\smart_contract\node_modules\ethers\src.ts\contract\contract.ts:768:39)
    at main (C:\Users\Web3_Proj1\smart_contract\scripts\deploy.js:5:30)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at runMain (C:\Users\Web3_Proj1\smart_contract\scripts\deploy.js:12:5) {

  code: 'INVALID_ARGUMENT',

  argument: 'key',

  value: 'deployed'

}

问题原因

报错源于你使用的ethers.js版本为v6,而视频及仓库代码基于旧版ethers(v5及以下)开发。ethers v6重构了合约部署API,原有的deployed()方法已被移除。

解决方案

修改scripts/deploy.js中的部署逻辑:

  • 旧版(v5)代码示例:
const contract = await ContractFactory.deploy();
await contract.deployed();
  • 替换为ethers v6兼容写法:
const contract = await ContractFactory.deploy();
await contract.waitForDeployment();
  • 若需获取合约地址,v6中可使用await contract.getAddress()(或直接访问contract.address,但推荐使用标准方法)

修改完成后,重新执行部署命令即可正常完成合约部署。

内容的提问来源于stack exchange,提问作者crazy88

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 06:47:32