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

@nbouvier/hardhat-configs-proxy

v0.0.11

Published

Contract addresses managment for Hardhat project

Downloads

19

Readme

Hardhat Configs Proxy

Hardhat Configs Proxy provides an easy way to keep track of your deployed contracts address on your favorite blockchain.

Getting started

Prerequisites

  • Setup your hardhat project

https://hardhat.org/hardhat-runner/docs/getting-started#quick-start

  • Install the peer dependencies.
npm install --save-dev ethers
npm install --save-dev @nomiclabs/hardhat-ethers
npm install --save-dev @openzeppelin/hardhat-upgrades

Installation

  1. Install the npm package.
npm install --save-dev @nbouvier/hardhat-configs-proxy
  1. Import the package in your hardhat.config.ts.
// Javascript
require('@nbouvier/hardhat-configs-proxy');

// Typescript
import '@nbouvier/hardhat-configs-proxy';

NB: The import should come after both @nomiclabs/hardhat-etherscan and @openzeppelin/hardhat-upgrades.

  1. Start to write some code !

Usage

Configs folder

All of your contracts addresses will be stored in the ./configs folder under a file named <network>.config as a JSON structure. Where network is your network name in your hardhat.config.ts.

If the config location does not exist, it will be created.

// ./configs/hardhat.config

{
    "ERC20-1": {
        "artifact": "ERC20",
        "address": "0x5FbDB2315678afecb367f032d93F642f64180aa3"
    },

    "ERC20-2": {
        "artifact": "ERC20",
        "address": "0x5FbDB2315678afecb367f032d93F642f64180aa3"
    }
}

NB: The address of a contract deployed behind a proxy is the one of the proxy, not the one of the implementation contract.

Deployment

Deploying a contract is made simple be providing the name of your contract to the deploy or deployProxy functions.

This name will be the key used in the config file. If the contract has already been deployed before under the same name, an entry will already be registered in the config file and hardhat-configs will load this contract for you instead of deploying a new one.

const { configs } = require("hardhat");
const assert = require("assert");

async function main() {
    // Deploying for the first time
    const myToken = await configs.deploy("ERC20", [ ...<constructor-args> ]);

    // Trying to deploy again under the same name
    const myToken2 = await configs.deploy("ERC20", [ ...<constructor-args> ]);
    
    assert(myToken.address == myToken2.address);
}

main();

NB: If you want to deploy your contract under the same name as a previously deployed one, you can still rename it or delete it from the config file.

The name you give to your contract must be the same as your contract's artifact. If it is not, you will need to provide the name of the artifact to use as the last argument.

const { configs } = require("hardhat");
const assert = require("assert");

async function main() {
    // Deploying a contract
    const myFirstToken = await configs.deploy("ERC20-1", [ ...<constructor-args> ], "ERC20");

    // Deploying the same contract under a different name
    const mySecondToken = await configs.deploy("ERC20-2", [ ...<constructor-args> ], "ERC20");
    
    assert(myFirstToken.address != mySecondToken.address);
}

main();

Upgrading a contract

In order to upgrade a contract to a new implementation you can use the upgradeProxy function.
You can upgrade with the same contract artifact or provide a different one as the last argument.

const { configs } = require("hardhat");

async function main() {
    // Upgrading a contract with the same artifact
    const myTokenUpgraded = await configs.upgradeProxy("ERC20");
    
    // Upgrading a contract with a different artifact
    const myTokenUpgradedTwice = await configs.upgradeProxy("ERC20", "ERC20Upgraded");
}

main();

Getting a contract

Once you deployed a contract, you can access it anytime using the getContract function with the name you gave to your contract as an argument.

const { configs } = require("hardhat");

async function main() {
    const myToken = await configs.getContract("ERC20");
}

main();

Getting the network

Sometime, knowing the used network might come handy in order to do specific operation wether you are running on a local, test or main network. Hence, the getNetwork function might ease your programming journey.

const { configs } = require("hardhat");

async function main() {
    const network = await configs.getNetwork();
}

main();

License

This plugin is released under the GNU GPL V3 License.