#8024·hardhat

hardhat-viem: support full viem Chain config via chainDescriptors

Author: schaableCreated Mar 3, 2026Updated Sep 29, 2026
Labelsstatus:needs-priority

This is a follow-up to #7907, which introduced fallback chain resolution for unknown chain IDs. That PR covers the common case, but more advanced scenarios - such as multicall, ENS, custom fees, formatters, or serializers - require a full viem Chain object.

Design doc: https://www.notion.so/nomicfoundation/HTTP-custom-chain-handling-for-hardhat-viem-302578cdeaf58025bff7e6d53cc54f50

Proposed solution

Add a viemChain field to ChainDescriptorUserConfig that accepts a viem Chain. When provided, hardhat-viem uses it directly, just like a chain loaded from viem/chains, and skips the fallback logic.

typescript
// hardhat.config.ts
import { defineChain } from "viem";

export default {
  chainDescriptors: {
    9876: {
      name: "MyChain",
      chainType: "generic",
      viemChain: defineChain({
        id: 9876,
        name: "MyChain",
        nativeCurrency: { name: "MYC", symbol: "MYC", decimals: 18 },
        rpcUrls: { default: { http: [] } },
        contracts: {
          multicall3: { address: "0x...", blockCreated: 123 },
        },
      }),
    },
  },
};

The type extension would live in hardhat-viem:

typescript
// v-next/hardhat-viem/src/type-extensions.ts
import type { Chain as ViemChain } from "viem";

declare module "hardhat/types/config" {
  export interface ChainDescriptorUserConfig {
    viemChain?: ViemChain;
  }
}

Notes

  • When viemChain is provided, it is used as-is. No contracts or extra fields are merged in (e.g. for OP Stack chains, the user must be explicit).
  • rpcUrls in the provided viemChain is ignored at runtime since hardhat-viem always overrides the transport, but it is required by viem's type. { default: { http: [] } } is sufficient.
  • There is intentional minor duplication between ChainDescriptorUserConfig.name and viemChain.name. These serve different purposes: the descriptor name is used by Hardhat, while viemChain.name is used by viem clients.