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-switch-network

v1.1.1

Published

Hardhat plugin to enable switching networks during runtime

Downloads

262

Readme

Hardhat Switch Network Plugin

npm GitHub Workflow Status Project license hardhat

Hardhat plugin for enabling on-the-fly network switching within your Hardhat scripts and tasks.

What

This plugin allows you to switch between networks dynamically during the execution of Hardhat tasks or scripts. This is particularly useful when you need to interact with different Ethereum networks without restarting your Hardhat node or re-running your scripts.

Installation

There are two ways to include this code into your project:

  1. Install the npm package
  2. Just copy/paste it

1. The npm Package Method

To install the plugin, use the following command:

npm install --save-dev hardhat-switch-network

or

yarn add -D hardhat-switch-network

Import the plugin in your hardhat.config.js:

require("hardhat-switch-network");

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

import "hardhat-switch-network";

2. The Copy/Paste Method

  • if you're using TypeScript, open your hardhat.config.ts and copy/paste the code from ./src/index.ts and ./src/type-extensions.ts
  • if you're using JavaScript, open your hardhat.config.js file, copy/paste the code from ./src/index.ts, turn imports into requires and strip it of types. Voila!

Tip 1: remove all the code related to providers you do not use on your project, e.g. if you're using ethers, remove web3 provider update. Tip 2: if you're using hardhat-viem, you can completely remove code that updates providers for ethers and web3

Required plugins

There are no required plugins. This plugin automatically detects which underlying Hardhat plugin for interacting with the Ethereum blockchain is being used and hooks into it. You just install this plugin and use it!

Currently supported Hardhat plugins for interacting with the Ethereum blockchain:

Tasks

This plugin does not add any new Hardhat tasks. It focuses on extending the functionality of existing tasks by enabling network switching.

Environment extensions

This plugin extends the Hardhat Runtime Environment by adding a switchNetwork function. This function allows you to switch to a different network during runtime.

import { HardhatRuntimeEnvironment } from "hardhat/types";

async function main(hre: HardhatRuntimeEnvironment) {
    // Switch to a different network
    await hre.switchNetwork("sepolia");

    // Now you can interact with the new network
}

Configuration

This plugin does not add any new configuration options to your hardhat.config.js or hardhat.config.ts files.

Usage

There are no additional steps you need to take for this plugin to work.

Install it and access switchNetwork through the Hardhat Runtime Environment anywhere you need it (tasks, scripts, tests, etc).

Support Open Source

Building and maintaining hardhat-switch-network requires significant time and effort, and your support can help keep this project alive and thriving. If you find this plugin helpful in your projects, please consider contributing to its ongoing development.

Contribute

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated. Go to CONTRIBUTING.md to learn about how to set up Hardhat's development environment.

Donate Cryptocurrency

If you're able, financial contributions are greatly appreciated and help cover the costs of development and support. You can donate using the following Ethereum-based tokens: ETH, USDT, USDC, wBTC, wETH.

Ethereum Wallet Address:

0xf35d9f86e5f620Dc8a6938b154E37FF23244Dff9

donate address

Your support is crucial in ensuring that hardhat-switch-network continues to grow and serve the community. Thank you for helping keep this project going!

Don't forget to give the project a star! :star:

Happy coding!