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-contract-prompts

v1.0.24

Published

Help create prompt for query your smartcontract view apis.

Downloads

4

Readme

hardhat-contract-prompts

It's project that build CLI prompt with your Solidity codes. It will be helpful for testing Solidity code.

Install

Intsall in hardhat project root directory.

npm i hardhat-contract-prompts

Usage

  1. Place solidity code to 'contracts' in hardhat project path.
  2. Import prompt.
import { ViewContractPrompt } from 'hardhat-contract-prompts';
  1. Generate prompt.
const vcp = new ViewContractPrompt();
  1. Set contract name, prompt message.
await vcp.prepare('CONTRACT_NAME', 'my prompts...');
  1. Execute.
// contract -> ethers.Contract
const res = await vcp.execute(contract);
console.log(res);
  1. Run script.
// It doesn't work in 'npx hardhat test'. Use 'hardhat run'.
$ npx hardhat run [script]

Example

Example 1 : Greeter

import { ViewContractPrompt } from './hardhat-prompt';

async function temp() {
    const Greeter = await ethers.getContractFactory("Greeter");
    const greeter = await Greeter.deploy("Hello, world!");
    await greeter.deployed();

    expect(await greeter.greet()).to.equal("Hello, world!");

    const setGreetingTx = await greeter.setGreeting("Hola, mundo!");
    await setGreetingTx.wait();

    const vcp = new ViewContractPrompt();
    await vcp.prepare('Greeter', 'greeter test prompts.');

    const res = await vcp.execute(greeter);
    console.log(res);
}

// npx hardhat run test/greeter.ts

Run

Example 2 : myERC20

import { ViewContractPrompt } from './hardhat-prompt';

async function temp() {
    const Token = await ethers.getContractFactory("Token");
    const token = await Token.deploy(ethers.utils.parseEther('100000000'), 'MyToken', 'MTK');
    await token.deployed();

    const vcp = new ViewContractPrompt();
    await vcp.prepare('Token', 'Token test prompts.');

    const res = await vcp.execute(token);
    console.log(res);
}

// npx hardhat run test/token.ts

Run

Example 3 : ethers.Contract

import { ethers } from 'hardhat';
import { ViewContractPrompt } from './hardhat-prompt';

const CONTRACT_NAME = 'myContract';
const CONTRACT_ADDRESS = '0x0000...';
const CONTRACT_ABI = [];

async function temp() {
    const provider = new ethers.providers.StaticJsonRpcProvider(
        "http://127.0.0.1:8545", {chainId: 1337, name: 'localhost'}
    );
    
    const vcp = new ViewContractPrompt();
    const contract = new ethers.Contract(CONTRACT_ADDRESS, CONTRACT_ABI, provider);

    await vcp.prepare(CONTRACT_NAME, 'My test hardhat prompt for view.');

    const res = await vcp.execute(contract);
    console.log(res);
}

Example 4 : InvokeContractPrompt

import { ethers } from 'ethers';
import { InvokeContractPrompt } from 'hardhat-contract-prompts'

const CONTRACT_NAME = 'myContract';
const CONTRACT_ADDRESS = '0x0000...';
const CONTRACT_ABI = [];

async function temp() {
    const signer = (await ethers.getSigners())[0];
    
    const icp = new InvokeContractPrompt();
    const contract = new ethers.Contract(CONTRACT_ADDRESS, CONTRACT_ABI, signer);
    
    await icp.prepare(CONTRACT_NAME, 'My test hardhat prompt for invoke.');
    
    const res = await icp.execute(contract);
    await res.wait();
    
    console.log(res);
}

Todo

  • [X] 1. Build View method
  • [X] 2. Build Invoke method
  • [ ] 3.
  • [ ] 4.