UNPKG

hardhat-deployed-records

Version:
46 lines (45 loc) 2.25 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const config_1 = require("hardhat/config"); const plugins_1 = require("hardhat/plugins"); const fs_1 = __importDefault(require("fs")); const constants_1 = require("../constants"); const list_1 = require("./list"); const helpers_1 = require("./helpers"); (0, config_1.task)("deployed-list", "List deployed of one network") .addOptionalParam("explorer", "blockchain's block explorer,such as 'https://etherscan.io/tx/'") .setAction(async (taskArgs, hre) => { // read configs from `hardhat.config.ts` const configs = hre.config.deployedRecords; // get network name const network = hre.network.name; // default value is `hardhat` // `31337` is the chainId of default `localhost` network. Reference: https://hardhat.org/hardhat-network/docs/reference#chainid // `localhost` network's chainId is not explicitly configured in `hardhat.config.ts` // so we use `31337` as default value const chainId = hre.network.config.chainId ?? 31337; // get block explorer const explorer = taskArgs.explorer != null ? taskArgs.explorer : (0, list_1.blockchainExplorer)(chainId); if (explorer == "") { throw new plugins_1.HardhatPluginError(constants_1.PLUGIN_NAME, "chain not support, please specify block explorer manually by using '--explorer https://etherscan.io/tx/'"); } // if manifest file not exists, throw an error const manifest = `${configs.deployedDir}/${network}/contracts.json`; if (!fs_1.default.existsSync(manifest)) { throw new plugins_1.HardhatPluginError(constants_1.PLUGIN_NAME, `'${manifest}' file not found`); } const content = fs_1.default.readFileSync(manifest, "utf-8"); let json = JSON.parse(content); const list = (0, helpers_1.flatJson)(json).map((element) => { return { Contract: element[0], Address: element[1], "Blockchain Explorer": element[1] == constants_1.DEFAULT_DEPLOYED_ADDRESS ? "" : explorer + element[1], }; }); console.table(list); });