hardhat-contract-prompts
TypeScript icon, indicating that this package has built-in type declarations

1.0.24 • Public • Published

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

스크린샷 2022-04-20 오전 12 55 19

스크린샷 2022-04-20 오전 12 55 36


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

스크린샷 2022-04-20 오전 12 56 00

스크린샷 2022-04-20 오전 12 56 59

스크린샷 2022-04-20 오전 12 57 13

스크린샷 2022-04-20 오전 12 58 01


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.

Package Sidebar

Install

npm i hardhat-contract-prompts

Weekly Downloads

1

Version

1.0.24

License

MIT

Unpacked Size

15.9 kB

Total Files

10

Last publish

Collaborators

  • dbadoy