Replies: 1 comment 1 reply
-
Hi @evbots. This is not possible right now. We want to add some way to programmatically create Hardhat contexts, which wouldn't modify the global scope and would probably be what you want. But we don't have that feature yet. Without knowing a lot about your app, my guess is that your best shot is to call Hardhat in a sub-process. For example, you can do something like this: const { exec } = require("child_process")
const child = exec("npx hardhat compile", { cwd: pathToProjectRoot })
// read stdout and stderr from child, wait for it to finish, etc. There's a lot to hate about this solution, and there are several ways it can be improved (like using |
Beta Was this translation helpful? Give feedback.
-
Hi hardhat community,
I'm attempting to use hardhat as a javascript library inside a web server to compile contracts "on the fly".
My web server does these things:
Each user request requires saving contract output in a different artifacts directory, which is why I need to pass in that config into an Environment constructor (as shown below in my example).
I am using hardhat successfully, but I've noticed that I'm not able to just create objects in local scope. I can't seem to create an
Environment
object without creating aHardhatContext
object, which appears to inject a variable into the global scope.Is there a way to use hardhat that does not inject objects into the global scope? This would address my worries that there is some kind of race condition happening inside global scope if the web server is serving multiple requests at the same time.
Thank you! Example below.
Beta Was this translation helpful? Give feedback.
All reactions