New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

hardhat-proxy

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hardhat-proxy

Hardhat plugin for integration with [proxy contract](./contracts/Proxy.sol).

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

hardhat-proxy

Hardhat plugin for integration with proxy contract.

Required plugins

What

This plugin brings the proxy contract to Hardhat, which allows you to manage the proxy contract in a simple way.

Installation

npm install --save-dev hardhat-proxy

Add the following statement to your hardhat.config.js:

require('hardhat-proxy')

Or, if you are using TypeScript, add this to your hardhat.config.ts:

import 'hardhat-proxy'

Configuration

You need to add the proxy contract address in hardhat.config.js.

Config example:

export default {
  proxies: {
    hardhat: '0x5FbDB2315678afecb367f032d93F642f64180aa3'
  }
}

Note: you need to manually add the output proxy address in the hardhat.config.js after running hardhat proxy:deploy

Usage

First, use Register in your implementation contract.

import 'hardhat-proxy/contracts/Register.sol';

contract Implementation is Register {
  function foo() public {
    // Doing something
  }
}

Second, override function register, and return constant LibRegister.REGISTER_SUCCESS.

import 'hardhat-proxy/contracts/Register.sol';
import 'hardhat-proxy/contracts/utils/LibRegister.sol';

contract Implementation is Register {
  function register() public override returns (bytes4 success) {
    _register(this.foo.selector);
    return LibRegister.REGISTER_SUCCESS;
  }
}

Last, use scripts or CLI to register it to proxy contract.

Scripts example:

import hre from 'hardhat'

await hre.proxy.bootstrap('0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9')

CLI example:

$ hardhat proxy:deploy --network localhost --impl 0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9

Tasks

This plugin implements a proxy and proxy:deploy task.

The proxy:deploy task can deploy a proxy contract to ethereum network.

$ hardhat proxy:deploy --network localhost

Proxy contract deployed in hardhat: 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512

The proxy task can register an implementation contract to proxy contract

$ hardhat proxy:deploy --network localhost --impl 0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9

┌────────────┬────────────────────────────────────────────┬────────────────────────────────────────────┐
│ Selector   │ Old implementation                         │ New implementation                         │
├────────────┼────────────────────────────────────────────┼────────────────────────────────────────────┤
│ 0xa4136862 │ 0x0000000000000000000000000000000000000000 │ 0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9 │
├────────────┼────────────────────────────────────────────┼────────────────────────────────────────────┤
│ 0x8d75376a │ 0x0000000000000000000000000000000000000000 │ 0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9 │
├────────────┼────────────────────────────────────────────┼────────────────────────────────────────────┤
│ 0x22df2236 │ 0x0000000000000000000000000000000000000000 │ 0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9 │
└────────────┴────────────────────────────────────────────┴────────────────────────────────────────────┘
OptionTypeDefaultDescription
implAddressundefinedThe implementation contract's address.

Environment extensions

This plugins adds a proxy object to the Hardhat Runtime Environment. You can use it in hardhat scripts.

declare module 'hardhat/types/runtime' {
  export interface HardhatRuntimeEnvironment {
    proxy: {
      address: string
      bootstrap: (impl: string) => Promise<TransactionResponse>
      deploy: () => Promise<Contract>
    }
  }
}
  • address: The proxy address of current network
  • bootstrap: Register implementation contract to proxy contract
  • deploy: Deploy proxy contract

Contract Introduction

TODO

Keywords

FAQs

Package last updated on 22 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc