hardhat-toolbox-viem

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

1|Updated Jun 16, 2026
One-click install
npx skills add https://github.com/gitforg/BlockChain-Chain-of-Custody --skill hardhat-toolbox-viem-gitforg
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: hardhat-toolbox-viem
Source: https://github.com/gitforg/BlockChain-Chain-of-Custody/tree/main/contracts/.agents/skills/hardhat-toolbox-viem
Command: npx skills add https://github.com/gitforg/BlockChain-Chain-of-Custody --skill hardhat-toolbox-viem-gitforg

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Writing Hardhat tests with untyped contract calls lets wrong arguments, wrong types, and invalid transactions slip through until runtime. This Skill shows how to use the viem integration from @nomicfoundation/hardhat-toolbox-viem so contract interactions are type-checked against the ABI at compile time and Ethereum-specific assertions are available out of the box. ## Core Features & Use Cases - Typed contract interaction: Deploy contracts with viem.deployContract, attach to existing ones with viem.getContractAt, and call read/write methods with full ABI type inference. - Ethereum-specific assertions: Verify reverts, custom errors, emitted events, and ETH balance changes via viem.assertions, including predicate-based argument matching and the anyValue helper. - Client access: Obtain public, wallet, and test clients from network.create() for reading chain state, sending transactions from different accounts, and dev-only operations. - Use Case: While testing a Counter contract, deploy it inside a loadFixture setup, assert that unauthorized callers revert with a custom error, and confirm the Increment event emits the expected argument. ## Quick Start Load the hardhat skill first, then ask the AI to write a Hardhat test that deploys a contract with viem.deployContract and asserts a revert using viem.assertions.

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 test a contract with viem in Hardhat?▼

Call network.create() to get the viem object, then use viem.deployContract("ContractName") to get a fully typed instance. Call read methods with contract.read.x() and write transactions with contract.write.inc(), with arguments type-checked against the ABI.

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

Use viem.assertions with the unawaited transaction promise, such as viem.assertions.revertWithCustomError(tx, contract, "Unauthorized") or viem.assertions.emitWithArgs(tx, contract, "Increment", [1n]). Argument positions 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 argument types or counts slip through without compile-time errors.

Does hardhat-toolbox-viem work with loadFixture?▼

Yes, viem.deployContract is the canonical deploy step inside a loadFixture setup function. Return the deployed contract from the fixture and call networkHelpers.loadFixture(deployFn) in your test to reuse the snapshot.

When should I use node:assert instead of viem.assertions?▼

Use node:assert/strict for plain TypeScript checks like equality, arrays, and types. Reserve viem.assertions for Ethereum-specific conditions such as reverts, custom errors, emitted events, and ETH balance changes.