hardhat-toolbox-viem

Test and interact with Ethereum contracts using viem clients and assertions in Hardhat.

2|Updated Jun 20, 2026
One-click install
npx skills add https://github.com/solomongetnet/eip-712-gasless --skill hardhat-toolbox-viem-solomongetnet
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: hardhat-toolbox-viem
Source: https://github.com/solomongetnet/eip-712-gasless/tree/main/contracts/.agents/skills/hardhat-toolbox-viem
Command: npx skills add https://github.com/solomongetnet/eip-712-gasless --skill hardhat-toolbox-viem-solomongetnet

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @nomicfoundation/hardhat-toolbox-viem.

What problem does it solve? Writing type-safe contract tests in Hardhat with viem requires knowing the exact client APIs, typed contract interaction patterns, and Ethereum-specific assertion helpers, which are easy to misuse without guidance. ## Core Features & Use Cases - Typed Contract Interaction: Deploy contracts with viem.deployContract, attach via viem.getContractAt, and call read/write methods with full ABI type checking. - Ethereum-Specific Assertions: Assert reverts, custom errors, emitted events, and ETH balance changes using viem.assertions with predicate and anyValue argument matching. - Use Case: While testing a Counter contract, deploy it inside a loadFixture setup, call counter.write.incBy([3n]) from different wallet accounts, and verify the Increment event fired with the expected arguments. ## Quick Start Load the hardhat skill first, then use this skill to write a viem-based test that deploys a contract and asserts a revert with a custom error.

Frequently Asked Questions about hardhat-toolbox-viem

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

FAQPage Schema
How do I deploy and interact with contracts using viem in Hardhat?▼

Use viem.deployContract from the connection returned by network.create() to get a fully typed contract instance. Call read methods like counter.read.x() and write methods like counter.write.inc(), with arguments type-checked against the ABI at compile time.

How do I assert reverts and events in Hardhat viem tests?▼

Use viem.assertions helpers such as revert, revertWith, revertWithCustomError, emit, and emitWithArgs, passing the unawaited transaction promise as the first argument. Argument matchers accept concrete values, predicate functions, or the anyValue helper.

Should I use walletClient.writeContract or viem.deployContract for contract calls?▼

Prefer the typed instance returned by viem.deployContract or viem.getContractAt. walletClient.writeContract has no ABI typing, so wrong arguments or value on non-payable functions slip through without TypeScript errors.

Does hardhat-toolbox-viem work with loadFixture for test setup?▼

Yes, viem.deployContract is the canonical deploy step inside a loadFixture setup function. Destructure viem and networkHelpers from network.create(), then call networkHelpers.loadFixture with your deploy function.

How do I check ETH balance changes in Hardhat viem tests?▼

Use viem.assertions.balancesHaveChanged with the unawaited transaction promise and an object mapping addresses to expected deltas. Positive values mean received ETH and negative values mean spent, before gas costs.