hardhat-toolbox-mocha-ethers

Guides ethers.js contract interaction and chai assertions in Hardhat Mocha tests.

Updated Jul 16, 2026
One-click install
npx skills add https://github.com/manjilagamacharyya-glitch/Blockchain-Lost-and-Found-App --skill hardhat-toolbox-mocha-ethers-manjilagamacharyya-glitch
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: hardhat-toolbox-mocha-ethers
Source: https://github.com/manjilagamacharyya-glitch/Blockchain-Lost-and-Found-App/tree/main/contracts/.agents/skills/hardhat-toolbox-mocha-ethers
Command: npx skills add https://github.com/manjilagamacharyya-glitch/Blockchain-Lost-and-Found-App --skill hardhat-toolbox-mocha-ethers-manjilagamacharyya-glitch

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @nomicfoundation/hardhat-toolbox-mocha-ethers.

What problem does it solve? Writing Hardhat tests with the ethers + Mocha toolbox involves many specific APIs—network.create(), ethers.deployContract, TypeChain-typed instances, and Ethereum-specific chai matchers—and getting the setup or assertion syntax wrong leads to confusing test failures. ## Core Features & Use Cases - Ethers Helpers: Covers provider queries, signers, ethers.deployContract with constructor args and custom signers, connect, payable calls, and getContractAt for deployed contracts. - Chai Matchers: Documents .to.emit, .to.be.revertedWith, .to.be.revertedWithCustomError, and .to.changeEtherBalance(s) from @nomicfoundation/hardhat-ethers-chai-matchers. - Impersonation & Fixtures: Shows ethers.getImpersonatedSigner for arbitrary addresses and loadFixture-based deployment patterns. - Use Case: When writing a test that asserts a non-owner cannot call a restricted function, use this Skill to produce await expect(counter.connect(banned).inc()).to.be.revertedWith("only the owner can increment the counter") with correct typing. ## Quick Start Write a Hardhat Mocha test that deploys my contract with ethers, checks it emits an event, and verifies unauthorized calls revert.

Frequently Asked Questions about hardhat-toolbox-mocha-ethers

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I deploy a contract in a Hardhat test with ethers?▼

Call ethers.deployContract with the contract name, optional constructor arguments as the second parameter, and an optional signer as the third. It returns a fully TypeChain-typed contract instance after running hardhat build to generate types.

How to test that a transaction reverts in Hardhat with chai?▼

Pass the unawaited transaction promise to expect and use .to.be.revertedWith("message") for revert strings or .to.be.revertedWithCustomError(contract, "ErrorName") with .withArgs(...) for custom errors. These matchers come from @nomicfoundation/hardhat-ethers-chai-matchers.

How do I assert a contract emits an event in Hardhat tests?▼

Use await expect(tx).to.emit(contract, "EventName") and chain .withArgs(...) to check argument values. Pass the transaction promise without awaiting it so the matcher can inspect the receipt.

Can I send a transaction from an arbitrary address in Hardhat tests?▼

Yes. Fund the address with networkHelpers.setBalance, then call ethers.getImpersonatedSigner(address) to get a signer without a separate impersonateAccount call. Connect that signer to the contract to send transactions.

Why is my Hardhat test contract instance not type-checked?▼

TypeChain types are generated from the compiled ABI, so run hardhat build before typechecking. Without fresh types, deployContract results and function arguments will not be validated against the latest contracts.