0

Is there any way to test user interaction with Metamask from a hardhat project? I understand that hardhat is a browser addin, but I want to test useraction between my contract and metamask interaction like signing etc and transaction approval.

there used used to a node module called node-hardhat, but it seems to be out of date and not maintained.

2 Answers 2

0

Yes sure, you can automate that process with automated testing in Hardhat. You do not need to add the testing wallet address to Metamakas and accept transactions manually. Same process could be done behind the scenes if your write a proper testing javascript file.

Start with this link:

https://hardhat.org/tutorial/testing-contracts

1
  • Actually my interest is in testing the user experience with metamask -- how it processes signing and transactions, not my solidity code, which I test in the usual way inside hardhat.
    – GGizmos
    Feb 18, 2023 at 15:43
0

You can run a local blockchain on your computer with npx hardhat node and connect the metamask to your own local network. You can follow this link to achieve this.

Afterwards, just run and connect your hardhat project to the network you just made on your local machine. You can use the command below:

npx hardhat run ./scripts/script.ts --network localNetworkAddress

Then you can run your local project from hardhat to deploy the contracts to the local network and use metamask to interact with it. You might want to setup your local network in a way that your wallet address has some ether in it from the start.

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.