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

Hardhat部署报错HH700:合约mood的Artifact未找到求助

PS E:\Block Chain Projects\SET OOD> npx hardhat run --network Goerli deploy.js
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
HardhatError: HH700: Artifact for contract "mood" not found.
    at Artifacts._handleWrongArtifactForContractName (E:\Block Chain Projects\SET OOD\node_modules\hardhat\src\internal\artifacts.ts:478:11)
    at Artifacts._getArtifactPathFromFiles (E:\Block Chain Projects\SET OOD\node_modules\hardhat\src\internal\artifacts.ts:593:19)
    at Artifacts._getArtifactPath (E:\Block Chain Projects\SET OOD\node_modules\hardhat\src\internal\artifacts.ts:275:17)
    at Artifacts.readArtifact (E:\Block Chain Projects\SET OOD\node_modules\hardhat\src\internal\artifacts.ts:58:26)
    at getContractFactory (E:\Block Chain Projects\SET OOD\node_modules\@nomiclabs\hardhat-ethers\src\internal\helpers.ts:99:22)
    at main (E:\Block Chain Projects\SET OOD\deploy.js:4:18)

我遇到了上述错误,无法生成Artifact文件,或者说Hardhat无法创建它。据我所知,npx hardhat compile应该会生成artifact文件,但这次没有生成。

相关文件截图:

  • mood.sol文件截图
  • deploy.js文件截图

请问我为什么会遇到这个问题,该如何解决?


问题分析与解决

可能原因

  • 合约名与文件名不匹配:Hardhat编译时会根据合约代码内contract的声明名称生成artifact,大小写完全敏感。如果.sol文件名是mood.sol,但合约内部声明的是Mood或其他名称,就会导致找不到对应artifact。
  • 编译过程失败:执行npx hardhat compile时如果存在语法错误、依赖缺失等问题,编译会直接终止,不会生成任何artifact文件。
  • 文件路径错误:合约文件未放在Hardhat默认的contracts/目录下,或者hardhat.config.js中自定义的合约路径配置错误,导致编译时未扫描到目标合约。
  • 缓存或旧编译文件干扰:之前的编译缓存、损坏的artifact文件可能导致新编译结果无法正常读取。

解决步骤

  1. 核对合约名与文件名
    打开mood.sol,确保合约声明的名称和文件名完全一致(包括大小写)。例如:

    // 合约名需与文件名mood.sol一致
    contract mood {
        // 合约代码
    }
    

    如果合约名是Mood,则在deploy.js中需使用getContractFactory("Mood"),而非"mood"。

  2. 手动执行编译并排查报错
    在项目根目录执行:

    npx hardhat compile
    

    仔细查看输出的错误信息(比如语法错误、引用库不存在等),修复后重新执行编译。

  3. 确认文件位置与配置
    确保mood.sol放在项目根目录的contracts/文件夹下;如果自定义了合约路径,检查hardhat.config.js中的paths.contracts配置是否指向正确目录。

  4. 清理缓存后重新编译
    删除项目中的artifacts/和cache/文件夹,再重新编译:

    # Windows系统
    rmdir /s /q artifacts cache
    # macOS/Linux系统
    rm -rf artifacts cache
    
    npx hardhat compile
    
  5. 检查deploy.js代码
    确认deploy.js中获取合约工厂的代码使用了正确的合约名称,示例:

    const moodContract = await ethers.getContractFactory("mood"); // 名称需与合约内声明完全一致
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.24 19:27:31