#hardhat-viem
This plugin integrates viem into Hardhat, adding a viem
object to each network connection.
#Installation
This plugin is part of the Viem Hardhat Toolbox. If you are using that toolbox, there's nothing else you need to do.
To install this plugin, run the following command:
npm install --save-dev @nomicfoundation/hardhat-viem
In your hardhat.config.ts
file, import the plugin and add it to the plugins
array:
import hardhatViem from "@nomicfoundation/hardhat-viem";
export default {
plugins: [hardhatViem],
};
#Usage
This plugin adds a viem
property to each network connection:
import { network } from "hardhat";
const { viem } = await hre.network.connect();
const publicClient = await viem.getPublicClient();
console.log(await publicClient.getBlockNumber());
const counter = await viem.deployContract("Counter");
await counter.write.inc();
console.log(await counter.read.x());
To learn more about using viem with Hardhat, read our guide.