hardhat/types#NetworkConfig TypeScript Examples

The following examples show how to use hardhat/types#NetworkConfig. 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: artifactUtils.ts    From index-coop-smart-contracts with Apache License 2.0 6 votes vote down vote up
// Adds a `gas` field to the ABI function elements so that ethers doesn't
// automatically estimate gas limits on every call. Halves execution time.
// (Borrowed from hardhat-ethers/src/internal/helpers.ts)
export function addGasToAbiMethods(
  networkConfig: NetworkConfig,
  abi: any[]
): any[] {
  const { BigNumber } = require("ethers") as typeof ethers;

  // Stay well under network limit b/c ethers adds a margin
  // Also need special setting logic for coverage b/c it compiles
  // before configuring the network with higher gas values.
  let gas: number;
  if (process.env.COVERAGE === "true") {
    const CoverageAPI: any = require("solidity-coverage/api");
    gas = new CoverageAPI().gasLimit as number;
  } else {
    gas = networkConfig.gas as number;
  }

  const gasLimit = BigNumber.from(gas).sub(1000000).toHexString();

  const modifiedAbi: any[] = [];

  for (const abiElement of abi) {
    if (abiElement.type !== "function") {
      modifiedAbi.push(abiElement);
      continue;
    }

    modifiedAbi.push({
      ...abiElement,
      gas: gasLimit,
    });
  }

  return modifiedAbi;
}
Example #2
Source File: index.ts    From hardhat-deploy with MIT License 6 votes vote down vote up
function createNetworkFromConfig(
  env: HardhatRuntimeEnvironment,
  networkName: string,
  config: NetworkConfig
): Network {
  const tags: {[tag: string]: boolean} = {};
  const tagsCollected = config.tags || [];
  for (const tag of tagsCollected) {
    tags[tag] = true;
  }

  const network = {
    name: networkName,
    config,
    live: config.live,
    saveDeployments: config.saveDeployments,
    zksync: config.zksync,
    tags,
    deploy: config.deploy || env.config.paths.deploy,
    companionNetworks: {},
  };
  networkFromConfig(env, network as Network, false);
  return network as Network;
}