Error when using approve function in a ERC20 contract

Hi everybody!

When I try to use approve function in a unit test (code below) for an ERC20 contract, but I’m getting the following error message:
Error: VoidSigner cannot sign transactions (operation=“signTransaction”, code=UNSUPPORTED_OPERATION, version=abstract-signer/5.1.0)

Here it is my test:

    describe("Transfer", () => {
        const ALLOWANCE_AMOUNT = 100;
        const AMOUNT_TO_TRANSFER = 100;
        let owner, spender, holder;
        beforeEach(async () => {
            [owner, spender, holder] = await ethers.getSigners();
        });
    it('Should allow spender contract get tokens from an holder account inside allowance limit', async () => {
            await this.contractToken.mint(holder.address, AMOUNT_TO_TRANSFER);
            await this.contractToken.connect(holder.address).approve(spender.address, ALLOWANCE_AMOUNT);
// supressed lines ...
    });
}

When I change the code (to use the owner account) as shown below, it runs:

await this.contractToken.approve(spender.address, ALLOWANCE_AMOUNT);

Any help would be great!

Thanks in advance.:

The signature is .connect(signer), not .connect(address).

So try this.contractToken.connect(holder).approve(...).

2 Likes

Hey @frangio , thank You very much! :pray:

1 Like

Thank you, this saved me a lot of time!

1 Like