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

Compile contracts outside of /src or /contracts directories #5760

Open
RohanNero opened this issue Sep 18, 2024 · 0 comments
Open

Compile contracts outside of /src or /contracts directories #5760

RohanNero opened this issue Sep 18, 2024 · 0 comments
Assignees

Comments

@RohanNero
Copy link

Describe the feature

I am using hardhat-viem to generate type definitions for my smart contracts every time they are compiled, however, it only works for contracts inside of my /src directory (/contracts).

Since I have integrated Hardhat into my Foundry project, I have smart contracts inside my /script and /test directories as well. Specifically, I'd like to import one of my deploy scripts for testing. It's highly likely that I will create hardhat deploy scripts written in Javascript/Typescript to accompany the hardhat tests, but currently, since all of my deploy scripts are written in Solidity, it would be extremely convenient if I could directly use them in my hardhat Typescript tests.

I know a similar issue was also considered in 2020 and was given this code snippet as a part of a possible solution:

subtask(
  TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS,
  async (_, { config }) => {
    const mainContracts = await glob(path.join(config.paths.root, "contracts/**/*.sol"));
    const testContracts = await glob(path.join(config.paths.root, "test/**/*.sol"));
    // and so on

    return [
      ...mainContracts,
      ...testContracts,
      // and so on
    ].map(path.normalize); // not sure if normalize is needed here
  }
);

However, since it is becoming more common for developers to use both Foundry and Hardhat in projects, it might also become more common for users to encounter this issue, see this StackExchange post as an example. For this reason, I think it would be beneficial to include support for this natively.

Search terms

compile artifacts types viem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Backlog
Development

No branches or pull requests

3 participants