npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hardhat-awesome-cli

v0.1.4

Published

Hardhat made awesome with a flexible CLI to help run test, deploy and more.

Downloads

420

Readme

license npm version

👷 hardhat-awesome-cli

#    #   ##   #####  #####  #    #   ##   #####         ##   #    # ######  ####   ####  #    # ######        ####  #      #
#    #  #  #  #    # #    # #    #  #  #    #          #  #  #    # #      #      #    # ##  ## #            #    # #      #
###### #    # #    # #    # ###### #    #   #   ##### #    # #    # #####   ####  #    # # ## # #####  ##### #      #      #
#    # ###### #####  #    # #    # ######   #         ###### # ## # #           # #    # #    # #            #      #      #
#    # #    # #   #  #    # #    # #    #   #         #    # ##  ## #      #    # #    # #    # #            #    # #      #
#    # #    # #    # #####  #    # #    #   #         #    # #    # ######  ####   ####  #    # ######        ####  ###### #

Hardhat made awesome with a flexible CLI to help run tests, deploy and more.

How to install this package

1. Install this package

With NPM

npm install hardhat-awesome-cli

Or with Yarn

yarn add hardhat-awesome-cli

2. Import/Require this package in your hardhat.config.js/.ts

Inside inside hardhat.config.js

require('hardhat-awesome-cli')

or inside hardhat.config.ts (Typescript)

import 'hardhat-awesome-cli'

Other option

git clone https://github.com/marc-aurele-besner/hardhat-awesome-cli

cd hardhat-awesome-cli

npm install

npm run build

npm link

in the hardhat project, you want to use this plugin

npm link hardhat-awesome-cli

Directories

CLI features

  • Run tests (Allow you you to run tests on all files or specific files in test/)

  • Run scripts (Allow you you to run scripts on specific files in scripts/)

  • Select scripts and tests to run (Allow you to select a script to execute and all or one test to perform afterward)

  • Flatten all your contract or a specific contract (offer to rename SPDX-License-Identifier -> SPDX-License-Flatten-Identifier to avoid multiple license identifier issue)

  • Run Forge test on all or single test contracts if forge setting is detected

  • Run coverage tests (Available only if solidity-coverage is installed and available as a task)

  • Setup chains, RPC and accounts

    • Add/Remove chains from the chain selection
    • Set RPC Url, private key or mnemonic for all or one chain
    • Add a custom chain to the current chain selection (currently these custom chains are not getting injected into hardhat networks)
    • See all config for activated chain
  • More settings

    • Exclude test file from the tests selection list

    • Exclude script file from the scripts selection list

    • Exclude script or contract file from the contract selection list

    • Install/Uninstall other Hardhat plugins

    • Create Github test workflows (for NPM and/or Yarn and for Hardhat test&coverage and/or Foundry test)

    • Create Foundry settings, remapping and test utilities

      Run forge test

          forge test
  • Create Mock contracts + (Deployment scripts, tests scripts and Foundry(Forge) test contracts (Missing test for MockProxyAdmin and MockTransparentUpgradeableProxy))

    • MockERC20
    • MockERC721
    • MockERC1155
    • MockERC20Upgradeable
    • MockERC721Upgradeable
    • MockERC1155Upgradeable
    • MockProxyAdmin
    • MockTransparentUpgradeableProxy
  • Get account balance

Current chain support

  • Hardhat local (default local network)
  • Ethereum - Mainnet (chainId: 1)
  • Ethereum - Ropstein (chainId 3)
  • Ethereum - Rinkeby (chainId 4)
  • Ethereum - Goerli (chainId 5)
  • Ethereum - Kovan (chainId 42)
  • Polygon - Mainnet (chainId 137)
  • Polygon - Mumbai (chainId 80001)
  • Binance Smart Chain - Mainnet (chainId 56)
  • Binance Smart Chain - Testnet (chainId 97)
  • Optimism - Mainnet (chainId 10)
  • Optimism - Testnet Kovan (chainId 69)
  • Avalanche - Mainnet (chainId 43114)

In 'More settings' you can also add a custom chain, create an issue or pull request to add other chains.

CLI optional flags

  • --add-activated-chain Add chains from the chain selection (default: "")
  • --add-foundry Create Foundry settings, remapping and test utilities (default: "")
  • --add-github-test-workflow Create Github test workflows (default: "")
  • --add-hardhat-plugin Add other Hardhat plugins (default: "")
  • --exclude-contract-file Exclude contract file from the contract selection list (default: "")
  • --exclude-script-file Exclude script file from the scripts selection list (default: "")
  • --exclude-test-file Exclude test file from the tests selection list (default: "")
  • --get-account-balance Get account balance (default: "")
  • --remove-activated-chain Remove chains from the chain selection (default: "")
  • --remove-hardhat-plugin Remove other Hardhat plugins (default: "")

Helper tools

Tools that you can use in your scripts and tests to make your life easier

Address Book

Create (if it does not exist) contractsAddressDeployed.json and contractsAddressDeployedHistory.json to store all the contracts you deployed, with the name of the contract, the contract address, the network name, the deployer address and the deployment date. The first file (contractsAddressDeployed.json) stores only the last contract for a given contract name and network name, while the second file (contractsAddressDeployedHistory.json) keeps a log of all the contracts deployed.

You can then retrieve your contract address in your tests scripts to run test on deployed contracts on live chains for example.

Import: javascript

const { addressBook, network } = require('hardhat')

typescript

import { addressBook, network } from 'hardhat'

Usage:

addressBook.saveContract(
        contractName: string,
        contractAddress: string,
        deployedNetwork: string,
        deployedBy: string,
        chainId: number = 0,
        blockHash?: string,
        blockNumber?: number,
        tag?: string,
        extra?: any,
        forceAdd = false as boolean
    )

addressBook.retrieveContract(contractName: string, deployedNetwork: string)

Example:

await addressBook.saveContract(
    'MockERC20',
    mockERC20.address,
    network.name,
    deployer.address,
    network.config.chainId,
    mockERC20.deployTransaction.blockHash,
    mockERC20.deployTransaction.blockNumber,
    'Test-MockERC20'
)

await addressBook.retrieveContract('MockERC20', network.name)

Return:

address: string

Retrieve a deployed contract object

Usage:


addressBook.retrieveContractObject(contractName: string, deployedNetwork: string)

Example:

await addressBook.retrieveContractObject('MockERC20', network.name)

Return:

{
    name: string
    address: string
    network: string
    deployer: string
    deploymentDate: Date
    chainId: number
    blockHah?: string
    blockNumber?: number
    tag?: string
    extra?: any
}

Retrieve Admin Proxy contract address deployed by @openzeppelin/hardhat-upgrades library

Usage:


addressBook.retrieveOZAdminProxyContract(chainId: number)

Example:

await addressBook.retrieveOZAdminProxyContract(network.config.chainId)

Return:

address: string

Retrieve all contracts deployed for a network name

Usage:


addressBook.retrieveContractHistory(deployedNetwork: string)

Example:

await addressBook.retrieveContractHistory(network.name)

Return:

[
    {
        name: string
        address: string
        network: string
        deployer: string
        deploymentDate: Date
        chainId: number
        blockHah?: string
        blockNumber?: number
        tag?: string
        extra?: any
    }
]

Clean the contractsAddressDeployed files by filtering a field and a value and remove these entry from the file, can be apply to both files or just the primary

Usage:


addressBook.cleanContractDeployed(field: TAddressBookFields, value: any, applyToPrimary: boolean = true, applyToHistory: boolean = true)

Example:

await addressBook.cleanContractDeployed('network', 'hardhat', true, true)

Directory Tree

hardhat-awesome-cli/
│   .eslintrc.js/
│   .mocharc.json/
│   .npmignore/
│   .prettierignore/
│   .prettierrc/
│   awesome-readme.config.js/
│   CONTRIBUTING.md/
│   LICENSE/
│   package-lock.json/
│   package.json/
│   README3.md/
│   tsconfig.json/
│   tsconfig.prod.json/
│   tslint.json/
└─── src/
└─── test/
   │   AwesomeAddressBook.ts/
   │   buildEnv.ts/
   │   buildExcludedFile.ts/
   │   buildFilesList.ts/
   │   buildFoundrySetting.ts/
   │   buildMockContracts.ts/
   │   buildNetworks.ts/
   │   buildWorkflows.ts/
   │   config.ts/
   │   index.ts/
   │   packageInstaller.ts/
   │   serveInquirer.ts/
   │   type-extensions.ts/
   │   types.ts/
   │   utils.ts/
   └─── githubWorkflows/
   └─── mockContracts/
   │   addressBook.test.ts/
   │   cli.test.ts/
   │   helpers.ts/
   └─── hardhat-cli/

🏗️ To do:

  • Improving documentation
  • Deployment contract generator
  • More Settings:
  • Handle directory for file exception
  • Setup slack API or email report to receive a copy of test result and contracts list deployed
  • Create a custom command
  • Improve all the tests, to test transfer, mint, burn (all basic ERC20, ERC721, ERC1155 functions)
  • Add test for AdminProxy and TransparentUpgradeableProxy
  • Offer to rename the Mock contract and set all constructor input (or initialize input) via cli
  • Verify that the input name does not conflict with inheritance
  • Rename the Mock file, contract name, deployment script, test scripts (and the test values)
  • Write more test with mocha to test the package functionality
  • Create contracts/, test/ and scripts/ folder if they don't exist when adding mock contracts
  • Remove package from hardhat config when remove