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-common-tools

v1.5.1

Published

A hardhat plugin providing common tools and functions for both ethers and viem projects

Downloads

53

Readme

hardhat-common-tools

A hardhat plugin providing common tools and functions for both ethers and viem projects.

Installation

Run this command to install it from NPM:

npm install --save-dev hardhat-common-tools@^1.5.1

Usage

This is a hardhat plugin, so the first thing to do is to install it in your hardhat.config.ts file:

require("hardhat-common-tools");

This is a polyfill for both ethers and viem, and intended to develop further plugins depending on it. The idea is that those plugins can leverage the tools provided by this plugin, so they don't have to split their development between ethers support and viem support.

The provided methods are the following:

  1. Retrieval of all the account signers (they'll become different objects, however):

    const signers = await hre.common.getSigners(); // The result is still an array.
    const signer0 = signers[0];
    // Or:
    const signer0 = await hre.common.getSigner(0); // Just a shortcut.
  2. Retrieval of an address from a signer (builds on the previous example):

    const address = hre.common.getAddress(signer0);
  3. Current chain id:

    const chainId = await hre.common.getChainId();
  4. Check whether the value is an address or not:

    const isAddress = await hre.common.isAddress(value);
  5. Instantiating an existing contract:

    const contract = await hre.common.getContractAt("MyContract", "0xTheContractAddress");
  6. Instantiating an existing ignition-deployed contract (if an ignition plugin is installed):

    await hre.ignition.getDeployedContract("MyIgnitionModule#MyContract");
    // Or with an explicit deployment id:
    await hre.ignition.getDeployedContract("MyIgnitionModule#MyContract", "someDeploymentId");
  7. Invoking a view/pure method via call:

    // Invoking a method via `call` with arguments (they come in an array).
    const result = await hre.common.call(contract, "mymethod", [arg1, arg2, ...whatever]);
  8. Invoking a view/pure method via send:

    // Invoking a method via `send` (transactionally) with arguments (they come in an array).
    // By default:
    await hre.common.send(contract, "withdraw", []);
    // Choosing an account:
    await hre.common.send(contract, "withdraw", [], {account: await hre.common.getSigner(0)});
    // All the transaction options (all of them are optional):
    await hre.common.send(contract, "withdraw", [], {
        account: await hre.common.getSigner(0),
        from: "0xAnAddress",
        gas: 400000, // A gas amount.
        gasPrice: 400000000000, // A pre-EIP-1559 gas price.
        maxFeePerGas: 400000000000, // An EIP-1559 max gas price.
        maxPriorityFeePerGas: 100000000000, // An EIP-1559 max priority price.
        value: 1000000000000000000, // A payment of 1 eth.
        eip155: true|false, // Whether to avoid a replay-attack.
    }); 
  9. Getting the address of a contract instance.

    // Get a contract somehow.
    const contract = await hre.ignition.getDeployedContract("SomeModule#SomeContract");
    const address = hre.common.getContractAddress(contract);
  10. Computing a keccak256 over a UTF-8 string.

    const hash = hre.ignition.keccak256("Hello World");
    // '0x592fa743889fc7f92ac2a37bb1f5ba1daf2a5c84741ca0e0061d243a2e6707ba'
  11. Getting the balance of an address:

    const balance = await hre.common.getBalance("0xAnAddress");
  12. Transferring native tokens to another account:

    // Case 1: Only an amount, and everything else by default.
    const tx = await hre.common.transfer("0xAnAddress", 1000000000000000000);
    
    // Case 2: Explicit arguments (`from` is not supported here;
    //         use `account` argument). All the arguments are
    //         optional.
    const tx = await hre.common.transfer("0xAnAddress", {
        account: await hre.common.getSigner(0),
        gas: 400000, // A gas amount.
        gasPrice: 400000000000, // A pre-EIP-1559 gas price.
        maxFeePerGas: 400000000000, // An EIP-1559 max gas price.
        maxPriorityFeePerGas: 100000000000, // An EIP-1559 max priority price.
        value: 1000000000000000000, // A payment of 1 eth.
        eip155: true|false, // Whether to avoid a replay-attack.
    })

More common functions

  1. Resetting the deployments (only present when @nomicfoundation/hardhat-ignition and the corresponding ignition plugin is installed):

    // provided hre.ignition exists:
    await hre.ignition.resetDeployment();