or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

contract-deployment.mdcontract-factories.mdcontract-instances.mdindex.mdprovider-access.mdsigner-management.md
tile.json

tessl/npm-nomicfoundation--hardhat-ethers

Hardhat plugin that integrates ethers.js into the Hardhat development environment with enhanced contract deployment and signer management capabilities

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@nomicfoundation/hardhat-ethers@4.0.x

To install, run

npx @tessl/cli install tessl/npm-nomicfoundation--hardhat-ethers@4.0.0

index.mddocs/

Hardhat Ethers

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.

Package Information

  • Package Name: @nomicfoundation/hardhat-ethers
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install --save-dev @nomicfoundation/hardhat-ethers

Core Imports

import 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],
};

Basic Usage

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");

Architecture

Hardhat Ethers is built around several key components:

  • Plugin System: Integrates with Hardhat's hook system to provide network-specific ethers instances
  • Enhanced Provider: HardhatEthersProvider extends ethers provider with Hardhat-specific functionality
  • Enhanced Signers: HardhatEthersSigner provides direct address access and Hardhat integration
  • Helper Functions: Convenient methods for contract deployment, factory creation, and signer management
  • Library Linking: Automatic library linking for contracts with dependencies
  • Artifact Integration: Seamless integration with Hardhat's artifact system for contract metadata

Capabilities

Contract Deployment

Deploy 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 {}

Contract Deployment

Contract Factories

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>>;

Contract Factories

Contract Instances

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>;

Contract Instances

Signer Management

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;
}

Signer Management

Provider Access

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>;
}

Provider Access

Core Types

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;
}