0

This part of own Q&A serial of posts which shares knowledge gained during work on one project

I was need to test my contract under different accounts and was looking for ways to do this.

2 Answers 2

1

In Hardhat case , u first need to get your hardhat blockchain simulated accounts using ethers.getSigners() function. Please know it returns an array with Signer Objects. When you have the accounts u can use the contract.connect method to connect your contract with the desired Signer Account u got from getSigners() function.

https://hardhat.org/hardhat-runner/plugins/nomiclabs-hardhat-ethers https://docs.ethers.io/v5/api/contract/contract/

let [account1,account2,account3] = await ethers.getSigners();
await contract.connect(account2).method();
0

ether.js allows to do this in this way:

 contract.connect(anotherUser).transfer();

Also I saw an option to create a separate contract which would act as Actor to verify test cases.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.