hardhat/types#CompilerOutputContract TypeScript Examples

The following examples show how to use hardhat/types#CompilerOutputContract. 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: artifact.ts    From balancer-v2-monorepo with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Read the build-info file for the contract `contractName` and extract the ABI and bytecode.
 */
function extractContractArtifact(task: Task, contractName: string): CompilerOutputContract {
  const buildInfo = task.buildInfo(contractName);

  // Read ABI and bytecode from build-info file.
  const contractSourceName = findContractSourceName(buildInfo, contractName);
  return buildInfo.output.contracts[contractSourceName][contractName];
}
Example #2
Source File: artifact.ts    From balancer-v2-monorepo with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Write the ABI and bytecode for the contract `contractName` to the ABI and bytecode files.
 */
function writeContractArtifact(task: Task, contractName: string, artifact: CompilerOutputContract): void {
  // Save contract ABI to file
  if (artifact.abi.length > 0) {
    const abiDirectory = path.resolve(task.dir(), 'abi');
    if (!existsSync(abiDirectory)) {
      mkdirSync(abiDirectory);
    }
    const abiFilePath = path.resolve(abiDirectory, `${contractName}.json`);
    writeFileSync(abiFilePath, JSON.stringify(artifact.abi, null, 2));
  }

  // Save contract bytecode to file
  const bytecodeDirectory = path.resolve(task.dir(), 'bytecode');
  if (!existsSync(bytecodeDirectory)) {
    mkdirSync(bytecodeDirectory);
  }
  const bytecodeFilePath = path.resolve(bytecodeDirectory, `${contractName}.json`);
  writeFileSync(bytecodeFilePath, JSON.stringify({ creationCode: artifact.evm.bytecode.object }, null, 2));
}
Example #3
Source File: task.ts    From balancer-v2-monorepo with GNU General Public License v3.0 6 votes vote down vote up
artifact(contractName: string, fileName?: string): Artifact {
    const buildInfoDir = this._dirAt(this.dir(), 'build-info');
    const builds: {
      [sourceName: string]: { [contractName: string]: CompilerOutputContract };
    } = this._existsFile(path.join(buildInfoDir, `${fileName || contractName}.json`))
      ? this.buildInfo(contractName).output.contracts
      : this.buildInfos().reduce((result, info: BuildInfo) => ({ ...result, ...info.output.contracts }), {});

    const sourceName = Object.keys(builds).find((sourceName) =>
      Object.keys(builds[sourceName]).find((key) => key === contractName)
    );

    if (!sourceName) throw Error(`Could not find artifact for ${contractName}`);
    return builds[sourceName][contractName];
  }