Skip to content

Conversation

@defiberrys
Copy link

Description

updated the code to use the public Hardhat API.

  • replaced import { Artifacts } from 'hardhat/internal/artifacts' with import { artifacts, Artifact } from 'hardhat' and rewrote getArtifact using artifacts.readArtifactSync.
  • switched from the non-existent ethers.getContractFactoryFromArtifact to ethers.getContractFactory(artifact.abi, artifact.bytecode, signer).

everything now works with the official Hardhat API without relying on internal modules.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Dependency changes
  • Code refactor / cleanup
  • Documentation or wording changes
  • Other

Checklist:

  • The diff is legible and has no extraneous changes
  • Complex code has been commented, including external interfaces
  • Tests are included for all code paths
  • The base branch is either master, or there's a description of how to merge

Copy link
Contributor

@jubeira jubeira left a comment

Choose a reason for hiding this comment

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

Thanks for sending this @defiberrys.

Curious how you got there. The helpers under pvt might not be perfectly written, but they don't seem to have any apparent issues either. Do you see any specific problem with the current implementation that brings in internal imports?

const artifact = getArtifact(contract);

const factory = await ethers.getContractFactoryFromArtifact(artifact, { signer: from, libraries });
const factory = await ethers.getContractFactory(artifact.abi, artifact.bytecode, from);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we also would need to send the libraries to link here: https://v2.hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-ethers

}

const artifacts = new Artifacts(artifactsPath);
return artifacts.readArtifactSync(contract.split('/').slice(-1)[0]);
Copy link
Contributor

Choose a reason for hiding this comment

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

So we don't need the artifactsPath anymore? how is the global artifacts linked to the path in this case, considering we have multiple workspaces in the monorepo?

@defiberrys
Copy link
Author

Curious how you got there. The helpers under pvt might not be perfectly written, but they don't seem to have any apparent issues either. Do you see any specific problem with the current implementation that brings in internal imports?

I switched to the public Hardhat API to avoid relying on internal modules, which are unstable and not guaranteed to maintain backward compatibility. using artifacts.readArtifactSync and ethers.getContractFactory ensures the code works with officially supported APIs, making it more robust and future-proof. the old helpers may work now, but they could break on Hardhat updates, whereas the public API is stable and officially supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants