When running tests and scripts, all functions are called by the first address provided by Hardhat.
I'd like to know if there's a way to change the calling address within the same test or script.
Thanks in advance!
You can use the connect()
method.
Code example from https://hardhat.org/tutorial/testing-contracts.html#using-a-different-account
const [owner, addr1, addr2] = await ethers.getSigners();
// Transfer 50 tokens from owner to addr1
await hardhatToken.transfer(addr1.address, 50);
// Transfer 50 tokens from addr1 to addr2
await hardhatToken.connect(addr1).transfer(addr2.address, 50);