hardhat/config#extendConfig TypeScript Examples

The following examples show how to use hardhat/config#extendConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.ts    From openzeppelin-upgrades with MIT License 6 votes vote down vote up
extendConfig((config: HardhatConfig, userConfig: Readonly<HardhatUserConfig>) => {
  if (!userConfig.defender || !userConfig.defender.apiKey || !userConfig.defender.apiSecret) {
    const sampleConfig = JSON.stringify({ apiKey: 'YOUR_API_KEY', apiSecret: 'YOUR_API_SECRET' }, null, 2);
    console.warn(
      `Defender API key and secret are not set. Add the following to your hardhat.config.js exported configuration:\n\n${sampleConfig}\n`,
    );
  }
  config.defender = userConfig.defender;
});
Example #2
Source File: index.ts    From openzeppelin-upgrades with MIT License 6 votes vote down vote up
extendConfig((config: HardhatConfig) => {
  for (const compiler of config.solidity.compilers) {
    compiler.settings ??= {};
    compiler.settings.outputSelection ??= {};
    compiler.settings.outputSelection['*'] ??= {};
    compiler.settings.outputSelection['*']['*'] ??= [];

    if (!compiler.settings.outputSelection['*']['*'].includes('storageLayout')) {
      compiler.settings.outputSelection['*']['*'].push('storageLayout');
    }
  }
});
Example #3
Source File: index.ts    From hardhat-kms-signer with MIT License 6 votes vote down vote up
extendConfig(
  (config: HardhatConfig, userConfig: Readonly<HardhatUserConfig>) => {
    const userNetworks = userConfig.networks;
    if (userNetworks === undefined) {
      return;
    }
    for (const networkName in userNetworks) {
      if (networkName === "hardhat") {
        continue;
      }
      const network = userNetworks[networkName]!;
      if (network.kmsKeyId) {
        config.networks[networkName].kmsKeyId = network.kmsKeyId;
      }
    }
  }
);
Example #4
Source File: index.ts    From hardhat-etherscan-abi with MIT License 5 votes vote down vote up
extendConfig(etherscanConfigExtender);
Example #5
Source File: index.ts    From hardhat-circom with GNU General Public License v3.0 5 votes vote down vote up
extendConfig((config: HardhatConfig, userConfig: Readonly<HardhatUserConfig>) => {
  const { root } = config.paths;

  const { inputBasePath, outputBasePath, ptau, circuits = [] } = userConfig.circom ?? {};

  if (circuits.length === 0) {
    throw new HardhatPluginError(
      PLUGIN_NAME,
      "Missing required circuits list, please provide via hardhat.config.js (circom.circuits) a list of circuit names to load from the inputBasePath"
    );
  }
  if (!ptau) {
    throw new HardhatPluginError(
      PLUGIN_NAME,
      "Missing required ptau location, please provide via hardhat.config.js (circom.ptau) the location of your ptau file"
    );
  }

  const defaultInputBasePath = path.join(root, "circuits");
  const defaultOutputBasePath = path.join(root, "circuits");

  const normalizedInputBasePath = normalize(root, inputBasePath) ?? defaultInputBasePath;
  const normalizedOutputBasePath = normalize(root, outputBasePath) ?? defaultOutputBasePath;

  const normalizedPtauPath = path.resolve(normalizedInputBasePath, ptau);

  config.circom = {
    inputBasePath: normalizedInputBasePath,
    outputBasePath: normalizedOutputBasePath,
    ptau: normalizedPtauPath,
    circuits: [],
  };

  for (const { name, version, protocol, beacon, circuit, input, wasm, r1cs, zkey, vkey } of circuits) {
    if (!name) {
      throw new HardhatPluginError(
        PLUGIN_NAME,
        "Missing required name field in circuits list, please provide via hardhat.config.js (circom.circuits.name)"
      );
    }

    const circuitPath = path.resolve(normalizedInputBasePath, circuit ?? `${name}.circom`);
    const inputPath = path.resolve(normalizedInputBasePath, input ?? `${name}.json`);
    const wasmPath = path.resolve(normalizedOutputBasePath, wasm ?? `${name}.wasm`);
    const r1csPath = path.resolve(normalizedOutputBasePath, r1cs ?? `${name}.r1cs`);
    const zkeyPath = path.resolve(normalizedOutputBasePath, zkey ?? `${name}.zkey`);
    const vkeyPath = path.resolve(normalizedOutputBasePath, vkey ?? `${name}.vkey.json`);

    config.circom.circuits.push({
      name: name,
      version: version !== 1 ? 2 : 1,
      protocol: protocol !== "plonk" ? "groth16" : "plonk",
      beacon: beacon != null ? beacon : "0000000000000000000000000000000000000000000000000000000000000000",
      circuit: circuitPath,
      input: inputPath,
      wasm: wasmPath,
      r1cs: r1csPath,
      zkey: zkeyPath,
      vkey: vkeyPath,
    });
  }
});
Example #6
Source File: index.ts    From hardhat-deploy with MIT License 4 votes vote down vote up
extendConfig(
  (config: HardhatConfig, userConfig: Readonly<HardhatUserConfig>) => {
    config.paths.deployments = normalizePath(
      config,
      userConfig.paths?.deployments,
      'deployments'
    );

    config.paths.imports = normalizePath(
      config,
      userConfig.paths?.imports,
      'imports'
    );

    if (userConfig.paths?.deploy) {
      let deployPaths = [];
      if (typeof userConfig.paths.deploy === 'string') {
        deployPaths = [userConfig.paths.deploy];
      } else {
        deployPaths = userConfig.paths.deploy;
      }
      config.paths.deploy = deployPaths.map((p) =>
        normalizePath(config, p, 'deploy')
      );
    } else {
      config.paths.deploy = [normalizePath(config, undefined, 'deploy')];
    }

    if (userConfig.namedAccounts) {
      config.namedAccounts = userConfig.namedAccounts;
    } else {
      config.namedAccounts = {};
    }

    config.deterministicDeployment = userConfig.deterministicDeployment;

    if (userConfig.external) {
      if (!config.external) {
        config.external = {};
      }
      if (userConfig.external.contracts) {
        const externalContracts: {artifacts: string[]; deploy?: string}[] = [];
        config.external.contracts = externalContracts;
        for (const userDefinedExternalContracts of userConfig.external
          .contracts) {
          const userArtifacts =
            typeof userDefinedExternalContracts.artifacts === 'string'
              ? [userDefinedExternalContracts.artifacts]
              : userDefinedExternalContracts.artifacts;
          externalContracts.push({
            artifacts: userArtifacts.map((v) => normalizePath(config, v, v)),
            deploy: userDefinedExternalContracts.deploy
              ? normalizePath(
                  config,
                  userDefinedExternalContracts.deploy,
                  userDefinedExternalContracts.deploy
                )
              : undefined,
          });
        }
      }
      if (userConfig.external.deployments) {
        config.external.deployments = {};
        for (const key of Object.keys(userConfig.external.deployments)) {
          config.external.deployments[key] = normalizePathArray(
            config,
            userConfig.external.deployments[key]
          );
        }
      }
    }

    for (const compiler of config.solidity.compilers) {
      setupExtraSolcSettings(compiler.settings);
    }

    const defaultConfig = {};
    if (userConfig.verify !== undefined) {
      const customConfig = userConfig.verify;
      config.verify = {...defaultConfig, ...customConfig};
    } else {
      config.verify = defaultConfig;
      // backward compatibility for runtime (js)
      // eslint-disable-next-line @typescript-eslint/no-explicit-any
      if ((userConfig as any).etherscan) {
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        config.verify.etherscan = (userConfig as any).etherscan;
      }
    }
  }
);