Use Hardhat & Foundry in the same project

Overview

Hardhat Foundry Starter

This is a solidity starter template which lets you use both, Hardhat and Foundry.

Why use both the tools?

Foundry has some awesome testing capabilities, thanks to cheatcodes, which can manipulate the state of the blockchain. However, I was missing out on some features offered by Hardhat. These include:

  • Compatibility by remix ide: I always use remix for deployment and manually testing contracts. However, I wasn't able to use foundry-style imports in remix (refer #2096). So, I decided to enable imports from node_modules, which are compatible with remix; and add remappings in foundry's config.
  • Ability to run a local node.
  • Writing tests in JS/TS: While writing tests in solidity is a better experience, sometimes we might want to replicate some JS behavior, which is present in dapps.

Hence, this template.

Getting Started

npm install
forge install

Foundry Instructions

Write forge tests in src/test.

forge build
forge test

Hardhat Instructions

Write hardhat tests in test.

npx hardhat accounts
npx hardhat compile
npx hardhat clean
npx hardhat test
npx hardhat node
npx hardhat help
REPORT_GAS=true npx hardhat test
npx hardhat coverage
npx hardhat run scripts/deploy.ts
TS_NODE_FILES=true npx ts-node scripts/deploy.ts
npx eslint '**/*.{js,ts}'
npx eslint '**/*.{js,ts}' --fix
npx prettier '**/*.{json,sol,md}' --check
npx prettier '**/*.{json,sol,md}' --write
npx solhint 'contracts/**/*.sol'
npx solhint 'contracts/**/*.sol' --fix

Etherscan verification

To try out Etherscan verification, you first need to deploy a contract to an Ethereum network that's supported by Etherscan, such as Ropsten.

In this project, copy the .env.example file to a file named .env, and then edit it to fill in the details. Enter your Etherscan API key, your Ropsten node URL (eg from Alchemy), and the private key of the account which will send the deployment transaction. With a valid .env file in place, first deploy your contract:

hardhat run --network ropsten scripts/sample-script.ts

Then, copy the deployment address and paste it in to replace DEPLOYED_CONTRACT_ADDRESS in this command:

npx hardhat verify --network ropsten DEPLOYED_CONTRACT_ADDRESS "Hello, Hardhat!"

Performance optimizations

For faster runs of your tests and scripts, consider skipping ts-node's type checking by setting the environment variable TS_NODE_TRANSPILE_ONLY to 1 in hardhat's environment. For more details see the documentation.

Credits

You might also like...

A fully-fledged Hardhat project template based on TypeScript.

Fully-Fledged Hardhat Project Template Based on TypeScript Installation It is recommended to install Yarn through the npm package manager, which comes

Dec 21, 2022

This is a fully functional DAO, a Web3 project made using Solidity, Hardhat, JS, Next.js, Openzeppelin, CSS, HTML, using the Rinkerby network!

My First DAO! This is made for a DAO-Tutorial via learnweb3.io This is a DAO, a decentralised autonomous organisation, essentially a more collective a

Jun 20, 2022

A simple To-do app project made using JavaScript ES6 and Webpack - Microverse. You can add, remove, check tasks, and remove all the tasks that were done at the same time. Feel free to see the live version, if you like it please give it a star!

To Do List a to do list javascript app buit using webpack and es6. Built With HTML CSS JavaScript Wepack Live Demo (if available) Live Demo Link Getti

Dec 17, 2022

A project where you can keep track of your goal's progress, and contribute to open source in the same time.

A project where you can keep track of your goal's progress, and contribute to open source in the same time.

Asakatsu-Website A project where you can keep track of your goal's progress, and contribute to open source in the same time. AsaKatsu is a Japanese te

Dec 27, 2022

Build a Full Stack Marketplace on Ethereum with React, Solidity, Hardhat, and Ethers.js

Build a Full Stack Marketplace on Ethereum with React, Solidity, Hardhat, and Ethers.js

Building a Digital Marketplace on Ethereum The technologies used in this workshop are React, Next.js, Tailwind CSS, HardHat, Solidity, and Ethers. Get

Nov 15, 2022

A Bed and Breakfast dApp run on Ethereum. Includes a token + schedule system (Solidity) and full front-end (React + ethers.js) built with Hardhat.

A Bed and Breakfast dApp run on Ethereum. Includes a token + schedule system (Solidity) and full front-end (React + ethers.js) built with Hardhat.

Hotel ETH - Watch Demo Video Hotel ETH A (fictional) Bed-and-Breakfast run on Ethereum Come Book a Room on Kovan or Rinkeby Networks View the Demo » C

Aug 20, 2022

An NFT Marketplace built with NextJS, Hardhat and Solidity

An NFT Marketplace built with NextJS, Hardhat and Solidity

🖼️ NFT Marketplace This is a fullstack DApp NFT Marketplace built as a study project to learn more about blockchain and smart contract development. M

Dec 31, 2022

Hardhat plugin to track gas on the transaction level

Hardhat plugin to track gas on the transaction level

hardhat-gas-trackooor Hardhat plugin to track gas on the transaction level. Example report Installation npm install hardhat-gas-trackooor --save-dev A

Jan 3, 2023

Decentralized twitter using Solidity, Ethereum, hardhat, ethers, IPFS, Next.JS, TypeScript, TailwindCSS.

DWITTER: Decentralized Twitter Check out the deployed version of this app at https://dwtr.wajeshubham.in Transactions on Ethereum are slow. Therefore,

Sep 2, 2022
Owner
Rajdeep Bharati
Web3.0 Engineer
Rajdeep Bharati
Solidity starter combining foundry and hardhat because both are great and I can't live without either...

Combination Pizza Hut & Taco Bell Foundry && HardHat starter template. Motivation I like them both. With this set-up we get: Unit tests written in sol

Cache Monet 32 Aug 23, 2022
Minimal template to get started with Foundry + Hardhat

Hardhat x Foundry Template Template repository for getting started quickly with Hardhat and Foundry in one project Getting Started Use Foundry: forge

Foundry 158 Jan 3, 2023
Generate deterministic fake values: The same input will always generate the same fake-output.

import { copycat } from '@snaplet/copycat' copycat.email('foo') // => '[email protected]' copycat.email('bar') // => 'Thurman.Schowalter668@

Snaplet 201 Dec 30, 2022
GitHub action to install Foundry

foundry-toolchain Action This GitHub action installs Foundry. Example workflow on: [push] name: test jobs: check: name: Foundry project ru

Bjerg 128 Jan 5, 2023
Library for Foundry VTT which provides easy access to dark comedy fantasy setting created by Richard Zadmar Woolcock

Library for Foundry VTT which provides easy access to dark comedy fantasy setting created by Richard Zadmar Woolcock. Current inclusions are a bestiary, edges, hindrances, and a journal with setting information, character creation, and more. The Savage Worlds Adventurers Edition Game System is the system this setting is designed for.

KevDog 2 Mar 18, 2022
A module to integrate World Anvil with Foundry Virtual Tabletop.

Foundry Virtual Tabletop - World Anvil Integration This module provides an integration with World Anvil for Foundry Virtual Tabletop, allowing you to

Foundry Virtual Tabletop 5 Sep 7, 2022
An implementation of the Dungeons & Dragons 5th Edition game system for Foundry Virtual Tabletop

An implementation of the Dungeons & Dragons 5th Edition game system for Foundry Virtual Tabletop.

Foundry Virtual Tabletop 103 Jan 2, 2023
🛠️ Easily track & compare gas costs estimated by Foundry on each of your Pull Requests!

?? ??️ Foundry Gas Diff Reporter Easily compare gas reports generated by Foundry automatically on each of your Pull Requests! How it works Everytime s

Romain Milon 133 Dec 28, 2022
A module for modifying sheet rolling functions on Foundry VTT Character sheets for D&D 5th Edition.

Ready Set Roll for 5e - FoundryVTT Module Ready Set Roll is a Foundry VTT module that accelerates the built in rolling system of the Foundry DnD5e sys

Mangó 17 Dec 12, 2022
A web3 starter project using Typescript, Hardhat, ethers.js and @web3-react

Starter React Typescript Ethers.js Hardhat Project This repo contains a Hardhat and React Dapp starter project. The React Dapp in the frontend dir of

ChainShot 39 Dec 31, 2022