Skip to content

Template for quickly getting started with developing Rust applications that leverage Foundry for EVM smart contract development

Notifications You must be signed in to change notification settings

foundry-rs/foundry-rust-template

Repository files navigation

Foundry Rust Monorepo Template

Rust Solidity Telegram Chat

Template for quickly getting started with developing Rust applications that leverage Foundry for EVM smart contract development.

Continuous Integration is already set up to test both your Rust and Solidity code, as well as ensure formatting and that your Rust bindings match the Solidity build artifacts.

Directory Structure

The project is structured as a mixed Rust workspace with a Foundry project under contracts/ and typesafe auto-generated bindings to the contracts under crates/bindings/.

├── Cargo.toml
├── app // <-- Your Rust application logic
├── contracts // <- The smart contracts + tests using Foundry
├── crates
    └── bindings // <-- Generated bindings to the smart contracts' abis (like Typechain)

Testing

Given the repository contains both Solidity and Rust code, there's 2 different workflows.

Solidity

Forge is using submodules to manage dependencies. Initialize the dependencies:

If you are in the root directory of the project, run:

forge install --root ./contracts

If you are in in contracts/:

forge install

Then, run the tests:

If you are in the root directory of the project, run:

forge test --root ./contracts

If you are in in contracts/:

forge test

Rust

cargo test

Generating Rust bindings to the contracts

Rust bindings to the contracts can be generated via forge bind, which requires first building your contracts:

forge build --root ./contracts
forge bind --bindings-path ./crates/bindings --root ./contracts --crate-name bindings

Any follow-on calls to forge bind will check that the generated bindings match the ones under the build files. If you want to re-generate your bindings, pass the --overwrite flag to your forge bind command.

Installing Foundry

First run the command below to get foundryup, the Foundry toolchain installer:

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

Then, in a new terminal session or after reloading your PATH, run it to get the latest forge and cast binaries:

foundryup

For more, see the official docs.

About

Template for quickly getting started with developing Rust applications that leverage Foundry for EVM smart contract development

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published