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_metamask_client2

v1.0.42

Published

Small project that lets you sign your transactions in hardhat script via metamask

Downloads

8

Readme

Hardhat Metamask Client

The Hardhat Metamask Client is a secure solution that addresses the issues associated with hardcoded account private keys in Hardhat during contract deployment or transaction execution. It incorporates an ethers signer that redirects you to your default browser, leveraging the metamask extension to execute your transaction.

Installation

To install the Hardhat Metamask Client, use the following command:

npm install hardhat_metamask_client

Usage

To utilize the Metamask Client, create a new instance by providing a configuration object. Here's an example:

let client = new MetamaskClient(config);

The configuration object should follow this format:

export type ClientConfig = {
    hardhatConfig?: any,
    networkName?: any,
    network?: any,
    ethers: any,
}

Note that the ethers field is mandatory. For other parameters, you have two possible approaches:

1. Providing hardhatConfig and networkName

The hardhatConfig parameter is the HardhatUserConfig object, usually defined in the hardhat.config.ts file.

The networkName should represent the network in which you want to execute your transaction. This network must be configured in the config object. For instance, if you wish to execute a transaction in the xyz network, your configuration should look as follows:

// hardhat.configuration.ts
export const config: HardhatUserConfig = {
    solidity: "...",
    networks: {
        xyz: {
            url: <RPC Url>,
            accounts: [
                <Private Key>
            ],
            chainId: <Chain Id>,
        },
        fantom: {
            ...
        },
    }
};

// sampleScript.ts
import config from '../hardhat.config';
import { ethers } from "hardhat";

let client = new MetamaskClient({
    hardhatConfig: config,
    networkName: "xyz",
    ethers: ethers
});

2. Providing the network

You can also directly provide the network object during task creation.

task("x", "")
    .setAction(async ({logData, reportGas}, {ethers, network}) => {
        let client: any = new MetamaskClient({ethers: ethers, network: network});
    });

Please note that the network configuration must include a URL, chainId, and at least one account. However, since this account won't be used to sign transactions, it can be any random private key if it's used only for signing transactions.

Here's an example illustrating how to deploy a contract using the Metamask signer:

let client = new MetamaskClient(config);
const Box = await ethers.getContractFactory("Box", {
    signer: await client.getSigner()
});
await Box.deploy();
client.close();  // Must be closed for the program to cease execution

Concluding Remarks

When you've completed your tasks, ensure to call client.close(). This stops the program from running continuously. The Hardhat Metamask Client offers a safer and more streamlined solution to contract deployment and transaction execution. Enjoy your secure and efficient development!