Skip to content

This project is a demonstration of using Hardhat with TypeScript to develop, compile, test, and deploy smart contracts.

Notifications You must be signed in to change notification settings

manishdait/ts-hardhat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hardhat Using Typescript

This project is a simple demonstration of using Hardhat with TypeScript to develop, compile, test, and deploy smart contracts.

Creating a Hardhat + TypeScript Project From Scratch

  1. Initialize NPM
mkdir ts-hardhat
cd ts-hardhat
npm init
  1. Install Hardhat
npm install --save-dev hardhat
  1. Create Hardhat Project
npx hardhat --init

Compile Your Contracts

To compile your Solidity smart contracts:

npx hardhat compile

This generates artifacts in the artifacts/ folder.

Run Tests

Your test files live inside the test/ folder.

To run tests:

npx hardhat test

Deploying the Contract

The deployment script is inside scripts/deploy.ts.

Example deploy.ts

import { network } from "hardhat";

const { ethers } = await network.connect();

async function main() {
  const contractFactory = await ethers.getContractFactory('FundMe');
  const fundMe = await contractFactory.deploy();
  const address = await fundMe.getAddress();

  console.log(`Contract deploy at ${address}`);
}

main()
  .then(() => process.exit(0))
  .catch((err) => process.exit(1))

Run Deployment

  • Deploy the contract
npx hardhat run scripts/deploy.ts
  • Deploy to a Custom Network (Example: Hardhat Local Node)

    1. Start node:
    npx hardhat node
    1. Deploy:
    npx hardhat run scripts/deploy.ts --network hardhatLocal

Summary of Commands

Purpose Command
Create project npx hardhat --init
Compile contracts npx hardhat compile
Run tests npx hardhat test
Deploy npx hardhat run scripts/deploy.ts --network <network>
Start local node npx hardhat node

About

This project is a demonstration of using Hardhat with TypeScript to develop, compile, test, and deploy smart contracts.

Topics

Resources

Stars

Watchers

Forks