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

describe("Token contract", function () {
  it("Deployment should assign the total supply of tokens to the owner", async function () {
    const [owner] = await ethers.getSigners();

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

    const hardhatToken = await Token.deploy();

    const ownerBalance = await hardhatToken.balanceOf(owner.address);
    expect(await hardhatToken.totalSupply()).to.equal(ownerBalance);

please, why do they have to enclose "owner" in a close bracket? I tried removing the square bracket, but the "owner. address" keeps returning undefine

1 Answer 1


ethers.getSigners() returns an array

this line:

const [owner] = await ethers.getSigners();

uses brackets because it is using destructuring

The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables.

so it is storing the first item of the array returned by getSigners in the constant owner

read more about destructuring here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.