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 templating capabilities in configuration variables #6162

Open
kanej opened this issue Jan 20, 2025 · 0 comments
Open

Support templating capabilities in configuration variables #6162

kanej opened this issue Jan 20, 2025 · 0 comments
Labels
status:ready This issue is ready to be worked on v-next A Hardhat v3 development task

Comments

@kanej
Copy link
Member

kanej commented Jan 20, 2025

We should consider methods of supporting patterns for Config Variables 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 added the v-next A Hardhat v3 development task label Jan 20, 2025
@kanej kanej added this to the Public Alpha Feature Rollout milestone Jan 20, 2025
@kanej kanej added this to Hardhat Jan 20, 2025
@github-project-automation github-project-automation bot moved this to Backlog in Hardhat Jan 20, 2025
@github-actions github-actions bot added the status:ready This issue is ready to be worked on label Jan 20, 2025
@kanej kanej moved this from Backlog to To-do in Hardhat Jan 20, 2025
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