Currently, in order to import contract types with hardhat-viem users need to import GetContractReturnType<ContractName$Type> from two sources (@nomicfoundation/hardhat-viem/types and the artifact path for the contract), the amount of imports grow as well if you need multiple contracts since you need one for each artifact, or you can use the ArtifactsMap but it's a handful to type GetContractReturnType<ArtifactsMap["ContractName"]> each time.
Adding a ContractTypesMap that returns GetContractReturnType<${ctd.typeName}["abi"]> to artifacts.d.ts by modifying generateArtifactsDefinition() and generateDuplicateArtifactsDefinition() can solve this problem. Users will only need to do import { ContractTypesMap } from "hardhat/types/artifacts"; and the contract type can be used like this
const contract: ContractTypesMap["ContractName"];
I have a fork ready for this as well, I've run the tests and updated the snapshots. Let me know if anything else needs to be done before I submit a PR.
Describe the feature
Currently, in order to import contract types with hardhat-viem users need to import
GetContractReturnType<ContractName$Type>
from two sources (@nomicfoundation/hardhat-viem/types
and the artifact path for the contract), the amount of imports grow as well if you need multiple contracts since you need one for each artifact, or you can use theArtifactsMap
but it's a handful to typeGetContractReturnType<ArtifactsMap["ContractName"]>
each time.Adding a
ContractTypesMap
that returnsGetContractReturnType<${ctd.typeName}["abi"]>
toartifacts.d.ts
by modifyinggenerateArtifactsDefinition()
andgenerateDuplicateArtifactsDefinition()
can solve this problem. Users will only need to doimport { ContractTypesMap } from "hardhat/types/artifacts";
and the contract type can be used like thisconst contract: ContractTypesMap["ContractName"];
I have a fork ready for this as well, I've run the tests and updated the snapshots. Let me know if anything else needs to be done before I submit a PR.
Search terms
viem contract type