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 🙏

© 2026 – Pkg Stats / Ryan Hefner

hardhat-openzeppelin-defender

v1.2.5

Published

Hardhat plugin openzeppelin defender

Readme

hardhat-openzeppelin-defender

Task

plugin created with the purpose of efficiently integrating openzeppelin defender modules with hardhat

Installation

yarn add --dev hardhat-openzeppelin-defender

or

npm install --save hardhat-openzeppelin-defender

Import the plugin in your hardhat.config.js:

require("hardhat-openzeppelin-defender");

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

import "hardhat-openzeppelin-defender";

Configuration

put the administration credentials of your openzeppelin defender OpenzeppelinDefenderCredential

module.exports = {
  OpenzeppelinDefenderCredential: {
    apiKey: API_KEY,
    apiSecret: API_SECRETE,
  }
};

Environment extensions

This plugin extends the Hardhat Runtime Environment by adding an OpenzeppelinDefender which contains all the modules of openzepelin defender

import { OpenzeppelinDefender } from "hardhat";

Usage

main samples repository

Utils

fromChainId

check and get the name of the network by its chainId

  OpenzeppelinDefender.Utils.fromChainId(97) // bsctest

AbiJsonString

extract the abi in string format from the contract interface

  OpenzeppelinDefender.Utils.AbiJsonString(abiInterface)

getAbiInterfaceParams

extracts the parameters of a function or event by using its abiInterface

abiInterface : smart contract interface

name : name of the event or function to which the parameters will be extracted

type : specifies whether the extraction of parameters will be from a function or an event

interface AbiInterfaceParams {
  abiInterface: Interface;
  name: string;
  type: "function" | "event";
}

//response

interface AbiInterfaceParamsResponse {
  name: string;
  signature: eventSignature | functionSignature;
  inputs: any[];
  fragment: string;
}

example

get the AbiInterfaceParams from the Transfer event of an ERC721 token

const params= {
  abiInterface: abiInterface,
  name: "Transfer",
  type: "event",
};
		
const result = OpenzeppelinDefender.Utils.getAbiInterfaceParams(params);

//response

/*{
  name: 'Transfer',
  signature: { eventSignature: 'Transfer(address,address,uint256)' },
  inputs: [
    { name: 'from', type: 'address' },
    { name: 'to', type: 'address' },
    { name: 'tokenId', type: 'uint256' }
  ],
  fragment: 'Transfer(address,address,uint256)'
}*/

AdminClient

Example 1

MyToken smart contract deployment and add to openzeppelin admin module

import { ethers,OpenzeppelinDefender } from "hardhat";

async function main() {
	
  const contractName='MyToken'
		
  const {chainId}=await ethers.provider.getNetwork()
		
  const Contract = await ethers.getContractFactory(contractName);
		
  const contract = await Contract.deploy();
		
  const {interface:abi,address}=await contract.deployed();
		
  //get the abi in json string using the contract interface
  const AbiJsonString= OpenzeppelinDefender.Utils.AbiJsonString(abi)
		
  //Obtaining the name of the network through the chainId of the network
  const networkName = await OpenzeppelinDefender.Utils.fromChainId(chainId);

  //add the contract to the admin
  const option={
    network:networkName ,
    address: address,
    name: contractName,
    abi:AbiJsonString
  }
		
  await OpenzeppelinDefender.AdminClient.addContract(option);
}

Example 2

Add MyToken to module admin and create a proposal

import { ethers, OpenzeppelinDefender } from "hardhat";

async function main() {

  const contractName = "MyToken";
		
  const {chainId}=await ethers.provider.getNetwork()
		
  const [owner] = await ethers.getSigners();
		
  const Contract = await ethers.getContractFactory(contractName);
		
  const contract = await Contract.deploy();
		
  const { interface: abi, address} = await contract.deployed();
		
  //obtaining the parameters of an event or function through the contract interface
  const params= {
    abiInterface: abi,
    name: "Transfer",
    type: "event",
  };
		
  const {inputs,name} =OpenzeppelinDefender.Utils.getAbiInterfaceParams(params);
		
  //adding a new contract to the admin and creating a proposal
  const option= {
    contract: {
      network: await OpenzeppelinDefender.Utils.fromChainId(chainId),
      address: address,
      name:contractName,
      abi: abi.format(ethers.utils.FormatTypes.json)
    },
    title: "Mint token",
    description: "minter 10 new tokens",
    type: "custom", 
    functionInterface: {
      name: name,
      inputs: inputs,
    },
    functionInputs: [owner.address,"100000000000000000000"],
    via: owner.address,
    viaType:'EOA'
  };
		
  await OpenzeppelinDefender.AdminClient.createProposal(option);
}

to know more methods of the AdminClient

RelayClient

Example 1

Creation of a relay and use of its address so that it assumes the MINTER_ROLE in the MyNft contract

import { ethers, OpenzeppelinDefender } from "hardhat";

async function main() {
 
  const contractName = "MyNFT";

  const {chainId}=await ethers.provider.getNetwork()

	//relay creation
  const RelayParams={
    name:'Relay_1',
    network: await OpenzeppelinDefender.Utils.fromChainId(chainId),
    minBalance: BigInt(1e18).toString(),
  };

  const {address:addressRelay}=await OpenzeppelinDefender.RelayClient.create(RelayParams);

  const Contract = await ethers.getContractFactory(contractName);

  //pass its address as a parameter so that it assumes MINTER_ROLE
  const contract = await Contract.deploy(addressRelay);
		
  const { interface: abi, address} =await contract.deployed();
		
  //add the contract to the admin	
  const option={
    network:await OpenzeppelinDefender.Utils.fromChainId(chainId),
    address: address,
    name: contractName,
    abi: abi.format(ethers.utils.FormatTypes.json)
  }
		
  await OpenzeppelinDefender.AdminClient.addContract(option);
}

to know more methods of the RelayClient

AutoTaskClint

Example 1

creating an autoTask

import {OpenzeppelinDefender} from "hardhat";

async function main() {

  const autoTaskOptions= {
    name: "exampleAutoTask",
    encodedZippedCode: await OpenzeppelinDefender.AutoTaskClint.getEncodedZippedCodeFromFolder("./openzeppelinDefender/autoTasks/exampleAutoTask"),
    trigger: {
      type: "webhook",
    },
    paused: false,
  };
  
  await OpenzeppelinDefender.AutoTaskClint.create(autoTaskOptions);
}

to know more methods of the AutoTaskClint

SentinelClient

Example 1

Creating a sentinel, to track all Transfer events of the Mytoken smart contract and assigning an autoTaskTrigger via its autoTaskId to the sentinel

import { ethers, OpenzeppelinDefender } from "hardhat";

async function main() {

  const contractName = "MyToken";

  const { chainId } = await ethers.provider.getNetwork();

  //deployment of the smart contract MyToken
  const Contract = await ethers.getContractFactory(contractName);
		
  const contract = await Contract.deploy();
		
  const { interface: abi, address, provider } = await contract.deployed();

  //getting the eventSignature from the Transfer event		
  const params= {
    abiInterface: abi,
    name: "Transfer",
    type: "event",
  };
		
  const {signature} =OpenzeppelinDefender.Utils.getAbiInterfaceParams(params);
		
  //Obtaining the name of the network through the chainId of the network
  const networkName = await OpenzeppelinDefender.Utils.fromChainId(chainId);
		
  //get the abi in json string using the contract interface
  const abiJsonString=OpenzeppelinDefender.Utils.AbiJsonString(abi);
		
  //add the contract to the admin
  const addContractOptions= {
    network: networkName,
    address: address,
    name: contractName,
    abi: abiJsonString,
  };
		
  await OpenzeppelinDefender.AdminClient.addContract(addContractOptions);
		
  //creating an autoTask
  const autoTaskOptions= {
    name: "exampleAutoTask",
    encodedZippedCode: await OpenzeppelinDefender.AutoTaskClint.getEncodedZippedCodeFromFolder("./openzeppelinDefender/autoTasks/exampleAutoTask"),
    trigger: {
     type: "webhook",
    },
    paused: false,
  };
		
  const { autotaskId } = await OpenzeppelinDefender.AutoTaskClint.create(autoTaskOptions);
		
  //creating a sentinel and assigning an autoTaskTrigger via its autoTaskId
  const sentinelOptions= {
    type: "BLOCK",
    network: networkName,
    confirmLevel: 12,
    name: "Sentinel",
    addresses: [address],
    abi: abiJsonString,
    paused: false,
    eventConditions: [signature],
    autotaskTrigger: autotaskId,
    notificationChannels: [""],
  };

  await OpenzeppelinDefender.SentinelClient.create(sentinelOptions);	
}

to know more methods of the AutoTaskClint