TypeError: Cannot read properties of undefined (reading 'address')

TypeError: Cannot read properties of undefined (reading 'address')

我在测试合同时遇到此错误。 类型错误:无法读取未定义的属性(读取 'address')

const{expect} = require("chai");
const hre = require("hardhat");


 describe("Token Contract", function(){

it("Deployment should assign the totalSupply of tokens to the owner", async function()
{
    const signers = await ethers.getSigner();
    const owner = signers[0];

    console.log("Signers Object:", owner);

    const Token = await ethers.getContractFactory("Token");

    const hardhatToken = await Token.deploy();

    const ownerBalance = await hardhatToken.balanceOf(owner.address);

    expect(await hardhatToken.totalSupply()).to.be.equal(ownerBalance);
});

});

你打错了。

// this is wrong
const signers = await ethers.getSigner();
// this is correct
const signers = await ethers.getSigners();

getSigner 仍然是一个有效的命令,但它不是 return 一个数组。这就是 signers[0] returned undefined.

的原因