Skip to content

Add an Easier Way to Import Contract Types for hardhat-viem #5375

Closed
@beepidibop

Description

@beepidibop

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

Search terms

viem contract type

Metadata

Metadata

Assignees

Labels

status:readyThis issue is ready to be worked on

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions