hardhat-toolbox-mocha-ethers

Guides writing Mocha and chai tests for Hardhat projects using ethers and TypeChain.

Updated Jul 18, 2026
One-click install
npx skills add https://github.com/TuxPenguin09/paychain --skill hardhat-toolbox-mocha-ethers-tuxpenguin09
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: hardhat-toolbox-mocha-ethers
Source: https://github.com/TuxPenguin09/paychain/tree/main/contracts/.agents/skills/hardhat-toolbox-mocha-ethers
Command: npx skills add https://github.com/TuxPenguin09/paychain --skill hardhat-toolbox-mocha-ethers-tuxpenguin09

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 specific patterns—top-level await connections, TypeChain-typed contracts, and Ethereum-specific chai matchers—that are easy to get wrong without a reference. ## Core Features & Use Cases - Connection Setup: Establishes one network.create() connection per test file with top-level await, since Mocha does not await describe callbacks. - Contract Interaction: Covers ethers.deployContract with constructor args and custom signers, typed function calls, connect for alternate signers, payable calls, and getImpersonatedSigner for arbitrary addresses. - Chai Matchers: Documents Ethereum-specific assertions including .to.emit, .to.be.revertedWith, .to.be.revertedWithCustomError, and .to.changeEtherBalance(s). - Use Case: When writing a test suite for a Solidity contract, use this Skill to correctly deploy typed contract instances inside loadFixture and assert on events, reverts, and balance changes. ## Quick Start Write a Hardhat test that deploys my Counter contract with ethers, checks that unauthorized callers revert, and asserts the Increment event emits with the right arguments.

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 Hardhat tests with ethers?▼

Use ethers.deployContract from the connection returned by network.create(), passing the contract name, optional constructor arguments array, and an optional signer. It returns a fully TypeChain-typed contract instance.

How do I test reverts and events in Hardhat with chai?▼

Pass the unawaited transaction promise into expect and use matchers like .to.be.revertedWith, .to.be.revertedWithCustomError, and .to.emit(contract, "EventName").withArgs(...). These come from the hardhat-ethers-chai-matchers plugin.

Why does my Hardhat Mocha test fail when awaiting inside describe?▼

Mocha does not await describe callbacks, so async setup inside them fails. Set up the connection at the top of the file with top-level await, creating one connection per test file.

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

Fund the address with networkHelpers.setBalance, then call ethers.getImpersonatedSigner(addr) to get a signer. It handles impersonation internally without a separate impersonateAccount call.

Does Hardhat ethers support TypeScript type checking for contracts?▼

Yes, TypeChain generates typed contract instances from the compiled ABI. Run hardhat build before typechecking so argument and return types are checked against the latest contracts.