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

Hardhat Contract Sizer

安装(windows环境):

yarn add --dev hardhat-contract-sizer

若安装报错:error Couldn’t find the binary git,需要安装Git并配置系统环境变量。path: D:\Program Files\Git\bin
若出现:unable to access ‘https://github.com/ethereumjs/ethereumjs-abi.git/’: OpenSSL SSL_read: Connection was reset, errno 10054
可设置:git config --global --add remote.origin.proxy “127.0.0.1:(proxy http port number)”

添加下列代码至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"],
    },
  },
};
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值