UNPKG

@nomicfoundation/hardhat-viem

Version:
30 lines (24 loc) 853 B
import type { HookContext, NetworkHooks } from "hardhat/types/hooks"; import type { ChainType, NetworkConnection } from "hardhat/types/network"; import { initializeViem } from "../initialization.js"; export default async (): Promise<Partial<NetworkHooks>> => { const handlers: Partial<NetworkHooks> = { async newConnection<ChainTypeT extends ChainType | string>( context: HookContext, next: ( nextContext: HookContext, ) => Promise<NetworkConnection<ChainTypeT>>, ) { const connection: NetworkConnection<ChainTypeT> = await next(context); connection.viem = initializeViem( connection.chainType, connection.provider, context.artifacts, context.config.chainDescriptors, connection.networkName, ); return connection; }, }; return handlers; };