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

Support configuration variables in Hardhat config everywhere it makes sense #6020

Open
Tracked by #6000
kanej opened this issue Dec 6, 2024 · 0 comments
Open
Tracked by #6000
Labels
status:ready This issue is ready to be worked on v-next A Hardhat v3 development task
Milestone

Comments

@kanej
Copy link
Member

kanej commented Dec 6, 2024

The new version of configuration variables should be usable at any point in the result object of hardhat.config.{js,ts}. Currently the types constrain this.

We should also consider methods of supporting patterns that are the equivalent of:

{
  url: `https://alchemy.com/api?key=${env.API_KEY}`
}

A suggestion was to support templating maybe with a template library:

{
  url: config.variable("https://alchemy.com/api?key={{API_KEY}}")
}

Though I would consider template literals:

{
  url: config.variable`https://alchemy.com/api?key=${"API_KEY"}`
}
function configurationVariableResolver(name: string): string | null {
  if (name === "API_KEY") {
    return "secret"
  }

  return null
}

const config = {
  variable: (strings: TemplateStringsArray, ...keys: string[]): string => {
    return strings.reduce((result, str, i) => {
        const key = keys[i - 1];
        
        return result + configurationVariableResolver(key) + str;
    });
  },
}

const example = {
  url: config.variable`https://alchemy.com/api?key=${"API_KEY"}`
}


console.log(example)
// {
//  "url": "https://alchemy.com/api?key=secret"
// } 

The template literal example here would need to be changed to return a ConfigVariable object so it could be resolved later, but the principle stands.

@kanej kanej mentioned this issue Dec 6, 2024
25 tasks
@fvictorio fvictorio added this to Hardhat Dec 6, 2024
@github-actions github-actions bot added the status:ready This issue is ready to be worked on label Dec 6, 2024
@github-project-automation github-project-automation bot moved this to Backlog in Hardhat Dec 6, 2024
@kanej kanej moved this from Backlog to To-do in Hardhat Dec 6, 2024
@kanej kanej added the v-next A Hardhat v3 development task label Dec 6, 2024
@kanej kanej added this to the Public Alpha milestone Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:ready This issue is ready to be worked on v-next A Hardhat v3 development task
Projects
Status: To-do
Development

No branches or pull requests

1 participant