{"id":20691961,"url":"https://github.com/ahmedali8/foundry-hardhat-template","last_synced_at":"2025-04-22T17:04:12.480Z","repository":{"id":107965979,"uuid":"543993233","full_name":"ahmedali8/foundry-hardhat-template","owner":"ahmedali8","description":"hardhat + foundry environment for testing and deployment of smart contracts","archived":false,"fork":false,"pushed_at":"2024-09-19T12:52:38.000Z","size":7652,"stargazers_count":10,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-29T17:01:54.105Z","etag":null,"topics":["anvil","blockchain","cast","ethereum","ethers","forge","foundry","hardhat","smart-contracts","solidity","template","typechain","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ahmedali8.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-10-01T10:58:38.000Z","updated_at":"2024-10-02T19:01:06.000Z","dependencies_parsed_at":"2023-11-08T12:39:17.487Z","dependency_job_id":"2f3a2943-15d4-4dc8-91df-a603d357390a","html_url":"https://github.com/ahmedali8/foundry-hardhat-template","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":"ahmedali8/hardhat-ts-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmedali8%2Ffoundry-hardhat-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmedali8%2Ffoundry-hardhat-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmedali8%2Ffoundry-hardhat-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmedali8%2Ffoundry-hardhat-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahmedali8","download_url":"https://codeload.github.com/ahmedali8/foundry-hardhat-template/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250285647,"owners_count":21405296,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["anvil","blockchain","cast","ethereum","ethers","forge","foundry","hardhat","smart-contracts","solidity","template","typechain","typescript"],"created_at":"2024-11-16T23:18:33.691Z","updated_at":"2025-04-22T17:04:12.455Z","avatar_url":"https://github.com/ahmedali8.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Foundry + Hardhat Template [![Open in Gitpod][gitpod-badge]][gitpod] [![Github Actions][gha-badge]][gha] [![Foundry][foundry-badge]][foundry] [![Hardhat][hardhat-badge]][hardhat]\n\n[gitpod]: https://gitpod.io/#https://github.com/ahmedali8/foundry-hardhat-template\n[gitpod-badge]: https://img.shields.io/badge/Gitpod-Open%20in%20Gitpod-FFB45B?logo=gitpod\n[gha]: https://github.com/ahmedali8/foundry-hardhat-template/actions\n[gha-badge]:\n  https://github.com/ahmedali8/foundry-hardhat-template/actions/workflows/ci.yml/badge.svg\n[hardhat]: https://hardhat.org/\n[hardhat-badge]: https://img.shields.io/badge/Built%20with-Hardhat-FFDB1C.svg\n[foundry]: https://getfoundry.sh/\n[foundry-badge]: https://img.shields.io/badge/Built%20with-Foundry-FFDB1C.svg\n\nA Foundry + Hardhat based template for developing Solidity smart contracts, with sensible defaults.\n\n#### Inspiration - [Hardhat Template](https://github.com/paulrberg/hardhat-template) and [Foundry Template](https://github.com/paulrberg/foundry-template)\n\n- [Hardhat](https://github.com/nomiclabs/hardhat): compile, run and test smart contracts\n- [TypeChain](https://github.com/ethereum-ts/TypeChain): generate TypeScript bindings for smart\n  contracts\n- [Ethers](https://github.com/ethers-io/ethers.js/): renowned Ethereum library and wallet\n  implementation\n- [Solcover](https://github.com/sc-forks/solidity-coverage): code coverage\n- [Forge](https://github.com/foundry-rs/foundry/blob/master/forge): compile, test, fuzz, debug and\n  deploy smart contracts\n- [Forge Std](https://github.com/foundry-rs/forge-std): collection of helpful contracts and\n  cheatcodes for testing\n- [Solhint](https://github.com/protofire/solhint): linter for Solidity code\n\n## Table of Contents\n\n- [Getting Started](#getting-started)\n- [Features](#features)\n  - [Sensible Defaults](#sensible-defaults)\n  - [GitHub Actions](#github-actions)\n- [Usage](#usage)\n  - [Pre Requisites](#pre-requisites)\n  - [Lint Solidity](#lint-solidity)\n  - [Foundry](#foundry)\n    - [Build or Compile](#build-or-compile)\n    - [Coverage](#coverage)\n    - [Clean](#clean)\n    - [Deploy](#deploy)\n    - [Gas Usage](#gas-usage)\n    - [Test](#test)\n    - [Notes](#notes)\n  - [Hardhat](#hardhat)\n    - [Run a Hardhat chain](#run-a-hardhat-chain)\n    - [Compile](#compile)\n    - [TypeChain](#typechain)\n    - [Test](#test-1)\n    - [Lint TypeScript](#lint-typescript)\n    - [Forking Mainnet](#forking-mainnet)\n    - [Coverage](#coverage-1)\n    - [Clean](#clean-1)\n    - [Deploy](#deploy-1)\n    - [Generate NATSPEC Doc](#generate-natspec-doc)\n    - [View Contracts Size](#view-contracts-size)\n    - [Verify Contract](#verify-contract)\n      - [Manual Verify](#manual-verify)\n      - [Verify Contract Programmatically](#verify-contract-programmatically)\n- [Syntax Highlighting](#syntax-highlighting)\n- [Using GitPod](#using-gitpod)\n- [Contributing](#contributing)\n- [Resources](#resources)\n\n## Getting Started\n\nClick the [`Use this template`](https://github.com/ahmedali8/foundry-hardhat-template/generate)\nbutton at the top of the page to create a new repository with this repo as the initial state.\n\nOr, if you prefer to install the template manually:\n\n```sh\n$ mkdir my-project\n$ cd my-project\n$ forge init --template ahmedali8/foundry-hardhat-template\n```\n\nRecommended node version is v20.x\n\nIf you have [nvm](https://github.com/nvm-sh/nvm) then run:\n\n```sh\n$ nvm use\n```\n\nThen, install dependencies\n\n```sh\n$ make setup # install Forge and Node.js deps\n```\n\nor\n\n```sh\n$ yarn install\n$ forge install\n```\n\nIf this is your first time with Foundry, check out the\n[installation](https://github.com/foundry-rs/foundry#installation) instructions.\n\n## Features\n\nThis template builds upon the frameworks and libraries mentioned above, so for details about their\nspecific features, please consult their respective documentations.\n\nFor example, for Hardhat, you can refer to the [Hardhat Tutorial](https://hardhat.org/tutorial) and\nthe [Hardhat Docs](https://hardhat.org/docs). You might be in particular interested in reading the\n[Testing Contracts](https://hardhat.org/tutorial/testing-contracts) section.\n\nFor example, for Foundry, you can refer to the [Foundry Book](https://book.getfoundry.sh/). You\nmight be in particular interested in reading the\n[Writing Tests](https://book.getfoundry.sh/forge/writing-tests.html) guide.\n\n### Sensible Defaults\n\nThis template comes with sensible default configurations in the following files:\n\n```text\n├── .editorconfig\n├── .eslintignore\n├── .eslintrc.yml\n├── .gitignore\n├── .prettierignore\n├── .prettierrc.yml\n├── .solcover.js\n├── .solhintignore\n├── .solhint.json\n├── .yarnrc.yml\n├── foundry.toml\n├── hardhat.config.ts\n└── remappings.txt\n```\n\n### GitHub Actions\n\nThis template comes with GitHub Actions pre-configured. Your contracts will be linted and tested on\nevery push and pull request made to the `main` branch.\n\nNote though that by default it injects `.env.example` env variables into github action's\n`$GITHUB_ENV`.\n\nYou can edit the CI script in [.github/workflows/ci.yml](./.github/workflows/ci.yml).\n\n## Installing Dependencies\n\nFoundry typically uses git submodules to manage dependencies, but this template uses Node.js\npackages because [submodules don't scale](https://twitter.com/PaulRBerg/status/1736695487057531328).\n\nThis is how to install dependencies:\n\n1. Install the dependency using your preferred package manager, e.g.\n   `yarn add dependency-name:dependency-url`\n   - Use this syntax to install from GitHub: `yarn add repo-name@github:username/repo-name#tag-name`\n2. Add a remapping for the dependency in [remappings.txt](./remappings.txt), e.g.\n   `dependency-name=node_modules/dependency-name`\n\nNote that OpenZeppelin Contracts is pre-installed, so you can follow that as an example.\n\n# Usage\n\n### Pre Requisites\n\nYou don't have to create a `.env` file, but filling in the environment variables may be useful when\ndeploying to testnet or mainnet or debugging and testing against a mainnet fork.\n\nFollow the example in [`.env.example`](.env.example). You can choose to use either a mnemonic or\nindividual private key by setting `MNEMONIC` or `PRIVATE_KEY` in your `.env` file.\n\nIf you don't already have a mnemonic, use this [bip39](https://iancoleman.io/bip39/) to generate one\nOr if you don't already have a private key, use this [vanity-eth](https://vanity-eth.tk/) to\ngenerate one.\n\n### Lint Solidity\n\nLint the Solidity code:\n\n```sh\n$ yarn lint:sol\n```\n\n## Foundry\n\nHere's a list of the most frequently needed commands.\n\n### Build or Compile\n\nBuild the contracts:\n\n```sh\n$ forge build\n```\n\n### Coverage\n\nGet a test coverage report:\n\n```sh\n$ forge coverage\n```\n\nTo get local HTMl reports:\n\n```\n$ make foundry-report\n```\n\nFor this to work, you need to have [lcov](https://github.com/linux-test-project/lcov) installed.\n\n### Clean\n\nDelete the build artifacts and cache directories:\n\n```sh\n$ forge clean\n```\n\n### Deploy\n\nDeploy to Anvil:\n\n```sh\n# Spin up an anvil local node\n$ anvil\n\n# On another terminal\n$ forge script scripts/foundry/DeployLock.s.sol:DeployLock \\\n  --fork-url localhost \\\n  --broadcast \\\n  -vvvv\n```\n\nFor this script to work for testnet or mainnet, refer to [Pre Requisites](#pre-requisites).\n\nFor instructions on how to deploy to a testnet or mainnet, check out the\n[Solidity Scripting tutorial](https://book.getfoundry.sh/tutorials/solidity-scripting.html).\n\n### Gas Usage\n\nGet a gas report:\n\n```sh\n$ forge test --gas-report\n```\n\n### Test\n\nRun the tests:\n\n```sh\n$ forge test\n```\n\nYou can also use\n[console.log](https://book.getfoundry.sh/faq?highlight=console.log#how-do-i-use-consolelog), whose\nlogs you can see in the terminal output by adding the `-vvvv` flag.\n\n## Notes\n\n1. Foundry piggybacks off [git submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules) to\n   manage dependencies. There's a [guide](https://book.getfoundry.sh/projects/dependencies.html)\n   about how to work with dependencies in the book.\n2. You don't have to create a `.env` file, but filling in the environment variables may be useful\n   when debugging and testing against a mainnet fork.\n\n## Hardhat\n\n### Run a Hardhat chain\n\nTo run a local network with all your contracts in it, run the following:\n\n```sh\n$ yarn chain\n```\n\n### Compile\n\nCompile the smart contracts with Hardhat:\n\n```sh\n$ yarn compile\n```\n\n### TypeChain\n\nCompile the smart contracts and generate TypeChain bindings:\n\n```sh\n$ yarn typechain\n```\n\n### Test\n\nRun the tests with Hardhat:\n\n```sh\n$ yarn test\n\nor\n\n$ yarn test:gas         # shows gas report and contract size\n\nor\n\n$ yarn test:trace       # shows logs + calls\n\nor\n\n$ yarn test:fulltrace   # shows logs + calls + sloads + sstores\n```\n\nOptional:\n\n- See the actual fiat currency rates by setting your coingecko api key from\n  [here](https://coinmarketcap.com/api/pricing/) in `.env` file or command.\n\n- Set custom gas price (gwei) in `.env` file or command or let it automatically fetched by\n  ethgasstationapi.\n\n```sh\n$ GAS_PRICE=20\n$ COIN_MARKET_CAP_API_KEY=\"your_api_key\"\n```\n\n### Lint TypeScript\n\nLint the TypeScript code:\n\n```sh\n$ yarn lint:ts\n```\n\n### Forking mainnet\n\nStarts a local hardhat chain with the state of the last `mainnet` block\n\n```sh\n$ yarn fork\n```\n\n### Coverage\n\nGenerate the code coverage report:\n\n```sh\n$ yarn coverage\n```\n\n### Clean\n\nDelete the smart contract artifacts, the coverage reports and the Hardhat cache:\n\n```sh\n$ yarn clean\n```\n\n### Deploy\n\nDeploy the contracts to Hardhat Network:\n\n```sh\n$ yarn deploy\n```\n\nDeploy the contracts to a specific network, such as the Goerli testnet:\n\n```sh\n$ yarn deploy:network goerli\n```\n\nFor more information on deploy check out repo\n[hardhat-deploy](https://github.com/wighawag/hardhat-deploy)\n\n### Generate Natspec Doc\n\nGenerate natspec documentation for your contracts by running\n\n```sh\n$ yarn hardhat dodoc\n```\n\nFor more information on Natspec\n[click here](https://docs.soliditylang.org/en/v0.8.12/natspec-format.html#natspec) and for dodoc\nrepo [click here](https://github.com/primitivefinance/primitive-dodoc)\n\n### View Contracts Size\n\n```sh\n$ yarn hardhat size-contracts\n```\n\nor turn on for every compile\n\n```sh\n$ CONTRACT_SIZER=true\n```\n\n## Verify Contract\n\n### Manual Verify\n\n```sh\n$ yarn hardhat verify --network \u003cnetwork\u003e DEPLOYED_CONTRACT_ADDRESS \"Constructor argument 1\" \"Constructor argument 2\"\n```\n\nFor complex arguments you can refer\n[here](https://hardhat.org/plugins/nomiclabs-hardhat-etherscan.html)\n\n```sh\n$ yarn hardhat verify --contract contracts/CONTRACT_NAME.sol:CONTRACT_NAME --network \u003cnetwork\u003e --constructor-args arguments.js DEPLOYED_CONTRACT_ADDRESS\n```\n\n### Verify Contract Programmatically\n\nVerify the contract using `verifyContract` function in [verify.ts](./utils/verify.ts)\n\nSet block explorer api key in `.env` file or using command, refer to `.env.example` for more\ninsight.\n\nExample deploy script with `verifyContract` function is\n[00_deploy_lock_contract.ts](./deploy/00_deploy_lock_contract.ts)\n\n## Syntax Highlighting\n\nIf you use VSCode, you can enjoy syntax highlighting for your Solidity code via the\n[vscode-solidity](https://github.com/juanfranblanco/vscode-solidity) extension.\n\n## Using GitPod\n\n[GitPod](https://www.gitpod.io/) is an open-source developer platform for remote development.\n\nTo view the coverage report generated by `yarn coverage`, just click `Go Live` from the status bar\nto turn the server on/off.\n\n## Contributing\n\nContributions are always welcome! Open a PR or an issue!\n\n## Thank You!\n\n## Resources\n\n- [Hardhat Documentation](https://hardhat.org/getting-started/)\n- [Foundry Book](https://book.getfoundry.sh/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmedali8%2Ffoundry-hardhat-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahmedali8%2Ffoundry-hardhat-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmedali8%2Ffoundry-hardhat-template/lists"}