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.
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.
// 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:
// 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
viemChainis 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). rpcUrlsin the providedviemChainis ignored at runtime sincehardhat-viemalways overrides the transport, but it is required by viem's type.{ default: { http: [] } }is sufficient.- There is intentional minor duplication between
ChainDescriptorUserConfig.nameandviemChain.name. These serve different purposes: the descriptor name is used by Hardhat, whileviemChain.nameis used by viem clients.
Source: NomicFoundation/hardhat