How to call contract functions on the user's behalf with hardhat?

Eg, suppose I want to test the approve() functionality with hardhat. The function assumes the caller is the wallet owner - how can I call the function on behalf of another user?

Hi, welcome to the community! :wave:

I think Hardhat integrates ethers.js, so you can have a check in ethers.js documentation:

Just Token.connect(Alice).approve(to,amount), the type of Alice should be a Signer.

1 Like

in hardhat testing, you can use connect function in ether.js library.
ex: contract.connect(user)

In Hardhat you can deploy to your local hardhat node. Which also provides you with multiple test accounts (address and private key) to use for function calls that require different senders.