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

Goerli网络部署合约遇ProviderError:地址参数非字符串问题求助

问题解决:部署Goerli网络代理合约时的地址参数错误

错误原因很明确:proxy.getAddress()是一个异步方法,直接调用它返回的是Promise对象而非字符串格式的地址,导致upgrades.erc1967.getImplementationAddress()和后续打印操作传入了非字符串参数,触发报错。

只需在调用proxy.getAddress()时加上await关键字,等待异步操作完成拿到字符串地址即可,修改后的代码如下:

const { ethers, upgrades } = require("hardhat");

async function main() {
  const VendingMachineV1 = await ethers.getContractFactory("VendingMachineV1");
  const proxy = await upgrades.deployProxy(VendingMachineV1, [100]);
  await proxy.waitForDeployment();

  // 加await获取字符串格式的代理地址
  const proxyAddress = await proxy.getAddress();
  const implementationAddress = await upgrades.erc1967.getImplementationAddress(
    proxyAddress
  );

  console.log("Proxy contract address: " + proxyAddress);
  console.log("Implementation contract address: " + implementationAddress);
}

main();

补充说明:Hardhat Ethers v6版本中,合约实例的getAddress()方法改为异步实现,这和旧版本的同步获取地址逻辑不同,是这类报错的常见诱因。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 13:23:10