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

@sebasgoldberg/hardhat-external

v0.0.5

Published

Hardhat plugin to work with external contract dependencies.

Downloads

5

Readme

hardhat-external-plugin

This plug-in it is used to add external contract already deployed dependencies to the project.

Hardhat external plugin.

What

This plugin will help you with:

  • For verified contracts it is possible to fetch abi from blockchain explorer and register as a model.
  • Once registered a model, it is possible to register multiple instances (contract addreses) for a model.
  • For each model it is possible to generate typechain classes.

Installation

npm install @sebasgoldberg/hardhat-external

Import the plugin in your hardhat.config.js:

require("@sebasgoldberg/hardhat-external");

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

import "@sebasgoldberg/hardhat-external";

Optional plugins

Tasks

external-add-model

In the following example we register the model BridgeToken using the abi found in the address 0xd586E7F844cEa2F87f50152665BCbc2C279D8d70. This model is registered in the test group (the group is optional). Aditionally, at the same time it is registered an instance BridgeDAIe, that it is going to use the same address, and the model BridgeToken.

$ npx hardhat external-add-model --address 0xd586E7F844cEa2F87f50152665BCbc2C279D8d70 --group test --instance BridgeDAIe --model BridgeToken

external-add-instance

In case we want to register multiple instance with the same model, we use external-add-instance.

In the following example we register an instance BridgeWETHe, that it is going to use the address 0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB, and the model BridgeToken. Note that to be possible to find the BridgeToken model, it is necessary to pass the group test as a parameter.

$ npx hardhat external-add-instance --instance BridgeWETHe --model BridgeToken --group test --address 0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB

Environment extensions

This plugin extends the Hardhat Runtime Environment by adding an external field whose type is External.

To get the Contract instance for both instances registered above, we simply do the following:

import { BridgeToken } from '../typechain-types'
// ...
const BridgeWETHe: BridgeToken = hre.external.getContract('BridgeWETHe', 'test') as BridgeToken
const BridgeDAIe: BridgeToken = hre.external.getContract('BridgeDAIe', 'test') as BridgeToken

Note that we are using the specific contract type BridgeToken generated using typechain.

Configuration

The models are created for each network (defined in taks using --network parameter).

In case the models registered for one network are the same for another network, it is possible to specify this with an alias. For this, we use @sebasgoldberg/hardhat-network-alias plugin.

In the following example, the models are registered for the hardhat network, and we want to use the same models for the localhost network.

const config: HardhatUserConfig = {
  // ...
  networkAliases:{
    "external-plugin": { // Note that the group must be "external-plugin".
      'localhost': 'hardhat'
    }
  }
  // ...

Note above that the group for aliases must be "external-plugin".

Additionally, by default all information related to models and instances are saved in the external folder.

If you need to change the path of this folder you can specify a relative or an absolute path:

const config: HardhatUserConfig = {
  // ...
  external:{
    path: 'other/location/for/external/plugin'
  },
  // ...