hardhat-contract-prompts
v1.0.24
Published
Help create prompt for query your smartcontract view apis.
Downloads
4
Maintainers
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
- Place solidity code to 'contracts' in hardhat project path.
- Import prompt.
import { ViewContractPrompt } from 'hardhat-contract-prompts';
- Generate prompt.
const vcp = new ViewContractPrompt();
- Set contract name, prompt message.
await vcp.prepare('CONTRACT_NAME', 'my prompts...');
- Execute.
// contract -> ethers.Contract
const res = await vcp.execute(contract);
console.log(res);
- 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.