create-nil-hardhat-project
v1.5.0
Published
<h1 align="center">create-nil-hardhat-project</h1>
Readme
Table of contents
🚀 Overview
This project houses create-nil-hardhat-project, a generator of Hardhat projects that work on top of =nil;.
🔧 Installation
Clone the repository:
git clone https://github.com/NilFoundation/nil.git
cd ./nil/create-nil-hardhat-projectInstall dependencies:
pnpm install⚙️ Configuration
- Create a
.envfile in the root directory based on the given.env.examplefile. - Update the
.envfile with the RPC URL. The default value corresponds to a locally running =nil; node. - Generate a private key and a new smart account using the hardhat default task
npx hardhat wallet create- Update the
.envfile with the private key and the smart account address.
🎯 Usage
To compile all smart contracts:
npx hardhat compileCreate a task for deploying the Incrementer.sol contract in ./tasks/deploy-incrementer.ts:
import { task } from "hardhat/config";
task("deploy-incrementer").setAction(async (taskArgs, hre) => {
const contract = await hre.nil.deployContract("Incrementer", []);
console.log("Incrementer contract deployed at address: " + contract.address);
await contract.write.increment([]);
const value = await contract.read.getValue([]);
console.log("Incrementer contract value: " + value);
});Import the task inside hardhat.config.ts:
import "./tasks/deploy-incrementer";To deploy the contract:
npx hardhat deploy-incrementerTo run all tests:
npm run testsMethods
Get default client:
const client = await hre.nil.getPublicClient();Get default smart account:
const smartAccount = await hre.nil.getSmartAccount();Create new smart account:
const smartAccount = await hre.nil.createSmartAccount({
topUp: true, // top up the account with tokens
});Contact deployment with params:
const contract = await hre.nil.deployContract("Incrementer", [0n], {
shardId: 1, // optionally set shard manually
feeCredits: 100_000_000n, // optionally set max fee credits
});Get and call deployed contract:
import { waitTillCompleted } from "./receipt";
const tokenContract = await hre.nil.getContractAt("Token", token0Address, {
smartAccount: smartAccount, // optionally set smart account for method calls
});
const txHash = await tokenContract.write.sendToken(["<to_addr", 1000n]);
// wait for the transaction to be completed
await waitTillCompleted(client, tx, {
waitTillMainShard: true, // wait for the main shard (useful for cross-shard transactions)
});
const balanace: bigint = await tokenContract.read.getTokenBalanceOf(["<address>"]);💪 Contributing
Contributions are always welcome! Feel free to submit pull requests or open issues to discuss potential changes or improvements.
🚧 Work in Progress
This project is currently under active development. Not all features are fully implemented and the project may behave unexpectedly in certain cases. If an issue arises when interacting with the project, open a new GitHub issue and detail the problem.
