Skip to content
/ evm-sol-hardhat-ts Public template

Ethereum with Solidity contracts using Hardhat testing framework in TypeScript

License

Notifications You must be signed in to change notification settings

abhi3700/evm-sol-hardhat-ts

Repository files navigation

Ethereum Solidity Hardhat Template

Ethereum + Solidity + Hardhat + Typechain

Ethereum with Solidity contracts using Hardhat testing framework in TypeScript

Use

  • Hardhat: compile and run the smart contracts on a local development network
  • TypeChain: generate TypeScript types for smart contracts
  • Ethers: renowned Ethereum library and wallet implementation
  • Waffle: tooling for writing comprehensive smart contract tests
  • Solhint: linter
  • Prettier Plugin Solidity: code formatter

This is a GitHub template, which means you can reuse it as many times as you want. You can do that by clicking the "Use this template" button at the top of the page.

Setup

1. Environment variables

  • Create a .env file with its values:
DEPLOYER_PRIVATE_KEY=<private_key_without_0x>
INFURA_API_KEY=<SECRET_KEY>
REPORT_GAS=<true_or_false>

2. Install the dependencies

  • Command:
    • M-1: $ npm install (install all the packages listed inside package.json)
    • M-2:$ npm install --save-dev @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers ethers hardhat-gas-reporter @openzeppelin/contracts typechain @typechain/ethers-v5 dotenv

3. Start writing contracts

  • Contracts in the "contracts/" folder.
  • Deployment scripts in the "deployment/" folder.
  • Testing (locally) scripts in the "scripts/" folder.

Usage

Pre Requisites

Before running any command, make sure to install dependencies:

$ npm install

Compile

Compile the smart contracts with Hardhat:

$ npx hardhat compile

Test

Run the Mocha tests:

$ npx hardhat test

Deploy contract to netowrk (requires Mnemonic/deployer_private_key and Infura API key)

npx hardhat run --network rinkeby ./deployment/deploy.ts

Validate a contract with etherscan (requires API ke)

npx hardhat verify --network <network> <DEPLOYED_CONTRACT_ADDRESS> "Constructor argument 1"

Added plugins

References

Thanks

If you like it, then you can put a star ⭐ on the repo.