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

[Typechain] Investigate how to support the attach method #6442

Merged
merged 8 commits into from
Mar 7, 2025

Conversation

ChristopherDedominici
Copy link
Contributor

@ChristopherDedominici ChristopherDedominici commented Mar 4, 2025

Fixes this

Depends on: NomicFoundation/hardhat#6400.
This dependency exists because test files are still being compiled and do not extend ethers. However, since test files should not be compiled, this is not an issue.

Copy link

changeset-bot bot commented Mar 4, 2025

🦋 Changeset detected

Latest commit: 8f2403d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@nomicfoundation/hardhat-typechain Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Mar 4, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hardhat ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 5, 2025 2:25pm

@@ -140,3 +142,37 @@ export function addJsExtensionsIfNeeded(content: string): string {
`import ${imports} from ${quote}${path}/index.js${quote};`,
);
}

function addSupportForAttachMethod(modifiedContent: string): string {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As with the other logic in this file, since Typechain is no longer maintained, we cannot open PRs to the repository, so we need to find a workaround.

The logic behind this code is:

  • Identify the files that extend ContractFactory
  • Modify these files to add support for the attach method
  • Add the required ethers import to support the attach method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this possibility in the design doc but discarded it due to several maintenance complications

@@ -140,3 +142,37 @@ export function addJsExtensionsIfNeeded(content: string): string {
`import ${imports} from ${quote}${path}/index.js${quote};`,
);
}

function addSupportForAttachMethod(modifiedContent: string): string {
const pattern = /class\s+(\w+)__factory/; // Pattern to find the contract name in factory files
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note for other reviewers because I checked it myself, \w+ is equivalent to [a-zA-Z0-9_]+. So it should cover all the characters allowed in contract names 👍

@ChristopherDedominici ChristopherDedominici added this pull request to the merge queue Mar 7, 2025
Merged via the queue into v-next with commit db98630 Mar 7, 2025
21 checks passed
@ChristopherDedominici ChristopherDedominici deleted the add-attach-support-in-hh-typechain branch March 7, 2025 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v-next A Hardhat v3 development task
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[Typechain] Investigate how to support the attach method
3 participants