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

@chromatic-protocol/hardhat-package

v0.0.1-dev.18

Published

You can easily pack and publish a hardhat project to interact deployed contracts.

Downloads

2

Readme

:package: @chromatic-protocol/hardhat-package

You can easily pack and publish a hardhat project to interact deployed contracts.

What

a nice cocktail :cocktail: of hardhat + typechain + hardhat-deploy + hardhat-ethers :smile:

  • compile contracts with @typechain/ethers-v6
  • deploy with hardhat-deploy
  • pack by this @chromatic-protocol/hardhat-package
  • finally publish your interfaces as a package.
  • and use this in any other related projects for example a web front-end project etc

Installation

npm install @chromatic-protocol/hardhat-package

Import the plugin in your hardhat.config.js:

require("@chromatic-protocol/hardhat-package")

Or if you are using TypeScript, in your hardhat.config.ts:

import "@chromatic-protocol/hardhat-package"

Required plugins

  • @nomicfoundation/hardhat-ethers
  • @typechain/hardhat
  • @typechain/ethers-v6 : supporting typechain targets
  • hardhat-deploy

Tasks

This plugin adds the package task to Hardhat:

npx hardhat package

Configuration

This plugin extends the HardhatUserConfig's TypechainPackageConfig object with an optional package field.

This is an example of how to set it:

config = {
  ...
  package: {
    outDir: 'dist',  // customize default output dir `dist` to other if you want.
    packageJson: 'package.json'  // specify package.json file to get partial meta information of your package 
  }
}

Usage

configure your hardhat.config

import { HardhatUserConfig } from 'hardhat/types'
import '@nomicfoundation/hardhat-ethers'

import '@typechain/hardhat'
import 'hardhat-deploy'

import '@chromatic-protocol/hardhat-package'

const config: HardhatUserConfig = {
  solidity: '0.8.17',
  defaultNetwork: 'hardhat',
  networks: {
    someNetwork: {
      // ... omittec
      saveDeployments: true
    }
  },
  // example configuration of typechain
  typechain: {
    outDir: 'typechain-types'
  },
  // example configuration of hardhat-deploy
  namedAccounts: {
    deployer: {
      default: 0
    }
  },
  // example configuration of @chromatic-finance/hardhat-package
  package: {
    outDir: 'dist'  // default without config.
    packageJson: 'package.sdk.json'  // default without config.
  }
}

export default config

setup scripts for deploying

This shows a sample script. see hardhat-deploy for details

import type { DeployFunction } from 'hardhat-deploy/types'
import type { HardhatRuntimeEnvironment } from 'hardhat/types'

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
  const { deployments, getNamedAccounts, network, ethers } = hre
  const { deploy } = deployments
  const { deployer } = await getNamedAccounts()

  await deploy('Greeter', {
    from: deployer,
    args: ['hi from Greeter contract!'],
    log: true
  })
}

export default func

func.id = 'deploy_greeter' // id required to prevent reexecution
func.tags = ['test', 'local']

compile & deploy

hardhat compile
hardhat deploy --network someNetwork

run the package task

this plugin prepares to publish. see outputs in outDir

hardhat package

publish your project

cd dist
# or npm link
npm publish  

use the published package

install

npm install my-hardhat-project

usage

import { getContract, getAllContracts, getContractNames } from 'my-hardhat-project'

let contract = getContract('Greeter', 'someNetwork')
contract.connect(signerOrProvider)
const res = await contract.greet()

const contracts = getAllContract('someNetwork')
contract = contracts['Greeter']
contract.connect(signerOrProvider)
const res = await contract.greet()

const contractNames = getContractNames('someNetwork')
const chainNames = getChainNames()

hardhat packaging options

src/types.ts