Hardhat plugin that integrates ethers.js into the Hardhat development environment with enhanced contract deployment and signer management capabilities
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
The Hardhat Ethers plugin integrates ethers.js into Hardhat, adding an ethers object to each network connection with enhanced functionality for smart contract development, testing, and deployment. It provides Hardhat-specific helpers for contract deployment, factory creation, signer management, and library linking while maintaining full compatibility with the standard ethers.js API.
npm install --save-dev @nomicfoundation/hardhat-ethersimport hardhatEthers from "@nomicfoundation/hardhat-ethers";For TypeScript types:
import type { HardhatEthers, FactoryOptions, Libraries } from "@nomicfoundation/hardhat-ethers/types";For configuration in hardhat.config.ts:
import hardhatEthers from "@nomicfoundation/hardhat-ethers";
export default {
plugins: [hardhatEthers],
};import { network } from "hardhat";
// Connect to network and access ethers
const { ethers } = await network.connect();
// Deploy a contract
const counter = await ethers.deployContract("Counter");
await counter.inc();
console.log(await counter.x());
// Get signers
const [signer] = await ethers.getSigners();
// Get contract factory
const Counter = await ethers.getContractFactory("Counter");Hardhat Ethers is built around several key components:
HardhatEthersProvider extends ethers provider with Hardhat-specific functionalityHardhatEthersSigner provides direct address access and Hardhat integrationDeploy contracts directly from project artifacts with constructor arguments, library linking, and deployment options.
function deployContract(
name: string,
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<ethers.Contract>;
function deployContract(
name: string,
args: any[],
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<ethers.Contract>;
interface DeployContractOptions extends FactoryOptions, ethers.Overrides {}Create ethers ContractFactory instances from project artifacts, ABI/bytecode, or contract names with library linking support.
function getContractFactory<A extends any[], I = ethers.Contract>(
name: string,
signerOrOptions?: ethers.Signer | FactoryOptions
): Promise<ethers.ContractFactory<A, I>>;
function getContractFactory<A extends any[], I = ethers.Contract>(
abi: any[] | Abi,
bytecode: ethers.BytesLike,
signer?: ethers.Signer
): Promise<ethers.ContractFactory<A, I>>;
function getContractFactoryFromArtifact<A extends any[], I = ethers.Contract>(
artifact: Artifact<Abi>,
signerOrOptions?: ethers.Signer | FactoryOptions
): Promise<ethers.ContractFactory<A, I>>;Get contract instances at specific addresses using project artifacts or ABI, with automatic signer binding.
function getContractAt(
nameOrAbi: string | any[] | Abi,
address: string | ethers.Addressable,
signer?: ethers.Signer
): Promise<ethers.Contract>;
function getContractAtFromArtifact(
artifact: Artifact,
address: string,
signer?: ethers.Signer
): Promise<ethers.Contract>;Access and manage signers for transactions, including account impersonation for testing.
function getSigners(): Promise<HardhatEthersSigner[]>;
function getSigner(address: string): Promise<HardhatEthersSigner>;
function getImpersonatedSigner(address: string): Promise<HardhatEthersSigner>;
interface HardhatEthersSigner extends ethers.Signer {
address: string;
}Access the enhanced Hardhat provider with network-specific capabilities and Hardhat RPC method support.
interface HardhatEthersProvider extends ethers.Provider {
getSigner(address?: number | string): Promise<HardhatEthersSigner>;
send(method: string, params?: any[]): Promise<any>;
}interface FactoryOptions {
signer?: ethers.Signer;
libraries?: Libraries;
}
interface Libraries {
[libraryName: string]: string | ethers.Addressable;
}
type DeployContractOptions = FactoryOptions & ethers.Overrides;
type HardhatEthers = typeof ethers & HardhatEthersHelpers;
interface HardhatEthersHelpers {
provider: HardhatEthersProvider;
getContractFactory: typeof getContractFactory;
getContractFactoryFromArtifact: typeof getContractFactoryFromArtifact;
getContractAt: typeof getContractAt;
getContractAtFromArtifact: typeof getContractAtFromArtifact;
deployContract: typeof deployContract;
getSigner: typeof getSigner;
getSigners: typeof getSigners;
getImpersonatedSigner: typeof getImpersonatedSigner;
}Install with Tessl CLI
npx tessl i tessl/npm-nomicfoundation--hardhat-ethers