-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
ESM Support / Runtime Network Change Support #3676
Comments
Hey @mihaic195, if I understood well, you want to run Hardhat on your backend service, in your case a serverless function of Next.Js, in order to call the Is that it ? |
@sshmaxime that is exactly right. |
Ok, then, could you explain exactly what your issue is about, other than Hardhat is not ESM compatible yet. |
Other than Hardhat is not ESM compatible yet, there is no straightforward way to change the network programmatically at runtime, except for using something like hardhat-change-network, which is a hackish way of doing it as per the package author. |
Hi @mihaic195, I think what you want is covered by #3043, #2797 and maybe also #3385. #2797 is in turn blocked by #3042, which is about being able to create different HREs in runtime with different configs. In your case, this would let you create a new HRE with the proper network for each verification. Sadly, we don't have an ETA for this. I'm going to assume that those issues cover this use case and close this one. Please let me know if you disagree. |
Version of Hardhat
2.12.7
What happened?
Related to: #3043
For example:
Multiple contracts with different configs are deployed programmatically, on a daily basis, on various chains. This is done through the browser using ethers.js and artifacts generated by the hardhat compilation in a next.js app.
The projects, contract tests, and hardhat config is written in TS.
I need a way to use the HRE in an ESM environment (e.g. next.js backend API) to be able to verify the said contracts using the
verify:verify
task. Since Next.js enforces ESM, I cannot use HRE in a next.js app.Minimal reproduction steps
commonjs
config.verify:verify
task once the endpoint is called.At this point, I'm faced with another issue:
hardhat
.So I need a way to change the network at runtime, which I was only able to do with the help of this package: https://github.com/dmihal/hardhat-change-network.
TL;DR
Because of the limitations above, I'm forced to have a separate verification microservice instead of creating a simple endpoint in a next.js app. I also have to use some sorcery to change the network at runtime.
In the end, it works, but it's far from ideal, as it requires much maintenance to do it this way.
I would gladly help in any way I can to overcome these issues if needed.
Search terms
hre, hardhat runtime environment, verification, esm, commonjs
The text was updated successfully, but these errors were encountered: