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

使用Yarn Hardhat部署MedicalRecords合约时测试报错求助

解决Hardhat + Ethers.js部署MedicalRecords合约的测试报错

错误核心信息

测试用例「合约部署成功」失败,抛出错误:

TypeError: no matching function (argument="key", value="address", code=INVALID_ARGUMENT, version=6.4.0)
at makeError (node_modules\ethers\src.ts\utils\errors.ts:656:21)
at assert (node_modules\ethers\src.ts\utils\errors.ts:680:25)
at assertArgument (node_modules\ethers\src.ts\utils\errors.ts:692:5)
at Interface.getFunctionName (node_modules\ethers\src.ts\abi\interface.ts:416:23)
at buildWrappedMethod (node_modules\ethers\src.ts\contract\contract.ts:334:34)
at BaseContract.getFunction (node_modules\ethers\src.ts\contract\contract.ts:783:22)
at Object.get (node_modules\ethers\src.ts\contract\contract.ts:714:39)
at Context. (test\MedicalRecords.test.js:13:28)

问题原因

这个错误由Ethers.js v6的特性或代码误用导致:

  • 你在测试代码第13行尝试访问合约实例的address,但Ethers.js v6中获取合约地址的语法已从contract.address改为contract.target
  • 或者你误将address当作合约的函数调用,但你的MedicalRecords合约ABI中并没有定义名为address的函数

修复步骤

  1. 打开test\MedicalRecords.test.js定位到第13行
  2. 根据代码逻辑调整:
    • 如果是获取合约地址:把contract.address替换为contract.target
    • 如果是调用合约函数:检查Solidity合约代码,确认是否存在名为address的函数,若不存在则修正为实际定义的函数名(比如getOwnerAddress这类)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 20:21:03