Skip to content

Foundry Template is a starter project for Ethereum development using Foundry. It includes key tools like Forge, Cast, Anvil, and Chisel, along with utilities for code quality (pre-commit), spell checking (typos), and changelog generation (git-cliff).

License

Notifications You must be signed in to change notification settings

qiaopengjun5162/foundry-template

Repository files navigation

Foundry Template

This is a template project to quickly bootstrap Ethereum application development using Foundry. Foundry is a blazing-fast, modular toolkit for Ethereum development written in Rust.

This template provides a basic setup for using Foundry's tools like Forge, Cast, Anvil, and Chisel. Whether you are building, testing, deploying, or interacting with smart contracts, this template will give you a solid foundation.

Foundry

Foundry is a fast, portable, and modular toolkit for Ethereum application development. It includes:

  • Forge: Ethereum testing framework (like Truffle, Hardhat, and DappTools).
  • Cast: A Swiss army knife for interacting with EVM smart contracts, sending transactions, and getting chain data.
  • Anvil: A local Ethereum node, similar to Ganache or Hardhat Network.
  • Chisel: A fast, utilitarian Solidity REPL.

Documentation

For detailed documentation, refer to the official Foundry book: Foundry Documentation

Project Setup

To get started with this project, make sure you have Foundry installed. If not, follow the instructions in the official documentation to set it up.

Install Foundry

First, install Foundry by running the following command:

curl -L https://foundry.paradigm.xyz | bash

Then, run the following command to install the necessary tools:

foundryup

Install Pre-commit

pre-commit is a tool to manage and maintain multi-language pre-commit hooks. It ensures that your code is checked before committing to the repository.

Install pre-commit using pipx:

pipx install pre-commit

After installation, run the following command to set up pre-commit in your project:

pre-commit install

Install Typos

typos is a tool for spelling checks in your project. It helps catch common spelling mistakes in your codebase.

Install typos with Cargo:

cargo install typos-cli

You can run it using:

typos

Install Git Cliff

git-cliff is a tool that generates changelogs from your commit history. It automatically creates a structured changelog for your project.

To install git-cliff, run:

cargo install git-cliff

Generate a changelog using:

git cliff --output CHANGELOG.md

Usage

Title: Initialize Foundry Project

Description: This set of commands creates a new directory named my-project, navigates into that directory, and then initializes a new Foundry project using a custom template from the specified GitHub repository.

mkdir my-project
cd my-project/
forge init --template https://github.com/qiaopengjun5162/foundry-template

Build the Project

To build the project, run the following command:

forge build

Run Tests

To run tests, use the following command:

forge test

Format Code

To format your Solidity code, use:

forge fmt

Take Gas Snapshots

To take gas snapshots of your transactions, use:

forge snapshot

Start Anvil (Local Ethereum Node)

To start an Anvil instance, use:

anvil

Deploy Contracts

To deploy contracts using Foundry, use:

forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>

Use Cast for Interactions

cast is a tool to interact with Ethereum smart contracts. You can use various subcommands:

cast <subcommand>

For more information about cast, run:

cast --help

Help Commands

For a list of available commands and options:

  • forge --help
  • anvil --help
  • cast --help

License

This project is licensed under the MIT License. See the LICENSE file for details.


Happy Coding! 🚀

About

Foundry Template is a starter project for Ethereum development using Foundry. It includes key tools like Forge, Cast, Anvil, and Chisel, along with utilities for code quality (pre-commit), spell checking (typos), and changelog generation (git-cliff).

Resources

License

Stars

Watchers

Forks

Packages

No packages published