Hardhat 获取合约编译后的文件大小

Hardhat Contract Sizer

安装(windows环境):

yarn add --dev hardhat-contract-sizer

添加下列代码至hardhat.config.js配置文件

require('hardhat-contract-sizer');
contractSizer: {
    alphaSort: true,
    runOnCompile: true,
    disambiguatePaths: false,
  }

执行:
1.

yarn run hardhat size-contracts

or
2.添加运行脚本至package.json

  "scripts": {
    "accounts": "hardhat accounts",
    "clean": "hardhat clean",
    "compile": "hardhat compile",
    "sizer": "hardhat size-contracts"
  },

执行结果:
在这里插入图片描述

hardhat.config.js:

require("@nomiclabs/hardhat-etherscan");
require("@nomiclabs/hardhat-waffle");
// get contract sizer
require('hardhat-contract-sizer');

// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
  const accounts = await hre.ethers.getSigners();

  for (const account of accounts) {
    console.log(account.address);
  }
});

// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more

/**
 * @type import('hardhat/config').HardhatUserConfig
 */
module.exports = {
  solidity: {
    version: '0.8.4',
    settings: {
      optimizer: {
        enabled: true,
        runs: 200,
      },
    },
  },
  contractSizer: {
    alphaSort: true,
    runOnCompile: true,
    disambiguatePaths: false,
  },
  networks: {
    tbsc: {
      url: "https://data-seed-prebsc-1-s1.binance.org:8545/",
      accounts:
        ["private key"],
    },
  },
};

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码

)">
< <上一篇

)">
下一篇>>