I'm attempting to setup some fairly comprehensive testing of a Solidity contract I wrote using hardhat & waffle, etc. One of the things I want to do is things like mint using various addresses while testing. If I go to Remix I can easily switch between which address is talking. This allows me to mint or try and test changing config settings from multiple Remix addresses, for instance. But how do we do that in a Hardhat testing script? Every interaction with the contract is always from the 1st address I've set:

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

I'd like to change that occasionally for my tests - to use addr2.address instead as an example. There's got to be a way, I just don't know the syntax to make it happen. Is it possible to flip between addresses that are talking to the contract from a test script? -- thanks for your help!

2 Answers 2


from the doc

If you need to send a transaction from an account other than the default one, you can use the connect() method provided by Ethers.js.

await greeter.connect(addr1).setGreeting("Hallo, Erde!");

in order to get the address account1.address you should use:

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

you need to insert

.connect(<different signer>)


const xyzContractFactory = await ethers.getContractFactory('xyz')
const xyzContract = await xyzContractFactory.deploy()
await xyzContract.deployed()

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

await xyzContract.connect(addr1).mint()
await xyzContract.connect(addr2).mint()

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.