类型错误:(0,ethers_1.getAddress)不是函数

问题描述 投票:0回答:2

我在部署智能合约时遇到此错误

const main = async() => {
  const contractFactory = await ethers.getContractFactory('TwitterContract');
  const contract = await contractFactory.deploy();
  //await contract.deployed();

  console.log("Contract deployed to: ", contract.address);
}

const runMain = async() => {
  try {
    await main();
    process.exit(0);
  } catch(error) {
    console.log(error);
    process.exit(1);
  }
}

runMain();

这是我用来部署智能合约的deploy.js脚本

"devDependencies": {
    "@nomicfoundation/hardhat-toolbox": "^3.0.0",
    "hardhat": "^2.15.0"
  },
  "dependencies": {
    "@ethersproject/contracts": "^5.7.0",
    "@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers@^0.3.0-beta.13",
    "chai": "^4.3.7",
    "dotenv": "^16.2.0",
    "ethers": "^5.5.0"
  }

这是依赖项

deployment solidity chai ethers.js hardhat
2个回答
0
投票

我有一段时间遇到同样的错误,有效的方法是从 Ethers v5 升级到 Ethers v6.6.2。所以更新你的以太版本,我认为它会起作用。不过,您必须对脚本进行更改,因为 ethers v6 附带了重大更改。你应该检查文档。

要更新,只需运行

yarn add ethers
即可获取最新版本,或者如果您想安装特定版本,您可以执行
yarn add [email protected] <<where 6.6.2 is the version>>. You can do the same with 
npm install ethers
and
npm install [email protected]`


0
投票

正如 swisscodemen 所说,要解决这个问题,我们需要将 ethers 版本更新到 V6,所以转到你的 package.json 文件,然后找到如下一行:

"ethers": "^5.6.7"

然后更改为:

"ethers": "^6.0.0"

运行

yarn
npm install
更新所有依赖项

© www.soinside.com 2019 - 2024. All rights reserved.