Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
beepidibop opened this issue Jun 11, 2024 · 2 comments
Closed

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

beepidibop opened this issue Jun 11, 2024 · 2 comments
Assignees
Labels
status:ready This issue is ready to be worked on

Comments

@beepidibop
Copy link
Contributor

beepidibop commented Jun 11, 2024

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

@kanej
Copy link
Member

kanej commented Jun 13, 2024

Hey @beepidibop, we would be open to a PR along these lines. Feel free to submit it.

@kanej kanej added status:ready This issue is ready to be worked on and removed status:triaging labels Jun 13, 2024
@beepidibop
Copy link
Contributor Author

Awesome, I've submitted the PR here.

@github-project-automation github-project-automation bot moved this from Backlog to Done in Hardhat Jun 25, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status:ready This issue is ready to be worked on
Projects
Archived in project
Development

No branches or pull requests

3 participants