Hardhat

Hardhat is a popular Ethereum development environment that provides a flexible and extensible framework for building smart contracts. This guide shows you how to deploy to LitVM using Hardhat.

Prerequisites

  • Node.js v18 or later

  • npm or yarn

  • A wallet with testnet zkLTC (see Add to Your Wallet)

  • Basic familiarity with JavaScript/TypeScript and Solidity


Create a New Project

# Create project directory
mkdir my-litvm-hardhat
cd my-litvm-hardhat

# Initialize npm
npm init -y

# Install Hardhat
npm install --save-dev hardhat

# Create Hardhat project
npx hardhat init

Select "Create a JavaScript project" (or TypeScript) and follow the prompts.


Install Dependencies


Configure for LitVM

Update hardhat.config.js:


Set Up Environment

Create a .env file (add to .gitignore!):


Write Your Contract

Create contracts/Counter.sol:


Compile

Expected output:


Test

Create test/Counter.js:

Run tests:


Deploy

Create scripts/deploy.js:

Deploy to LitVM testnet:


Verify Contract

The final 0 is the constructor argument (initial count).


Interact with Contract

Create scripts/interact.js:

Run:


Using Hardhat Console

Interactive testing:

Then in the console:


Gas Reporting

Install gas reporter:

Add to hardhat.config.js:

Run tests to see gas usage:


Common Issues

"Insufficient funds for gas"

Get testnet zkLTC from the faucet.

"Network not configured"

Ensure litvm_testnet is in your hardhat.config.js networks.

"Invalid chainId"

Update the chainId in config once official values are released.

"Nonce too high"

Reset your account nonce in MetaMask or wait for pending transactions.


TypeScript Support

For TypeScript projects, create hardhat.config.ts:


Next Steps

  • Deploy ERC-20 or ERC-721 tokens

  • Set up Foundry for faster compilation

  • Try Remix for browser-based development

  • Explore the LitVM ecosystem


Resources

Last updated