Hardhat specifies that to use a different account for contract interactions you should use the connect()
method, passing it a Signer, as such:
const [owner, addr1] = await ethers.getSigners();
/* ... */
await greeter.connect(addr1).setGreeting("Hello!");
Where greeter
is the contract instance.
However, when I use a Signer as they specify to, I get the following error:
Error: invalid address or ENS name (argument="name", value="<SignerWithAddress 0x59F...34C>", code=INVALID_ARGUMENT, version=contracts/5.6.0)
The internet says to use an address, such as this issue suggesting to use something like addr1.address
. But when I do, the following error results:
VoidSigner cannot sign transactions (operation="signTransaction", code=UNSUPPORTED_OPERATION, version=abstract-signer/5.6.0)
How can I switch signers/accounts when making contract calls with ethers.js and Hardhat?