Setting Up a Foundry Project and Installing Open-Zeppelin at a Specific Version

Yield DevYield Dev
1 min read

Installing

Foundry is an excellent modern framework for developing and testing solidity smart contracts. One of the primary benefits is being able to write tests directly in solidity.

First, we need to install the toolchain installer

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

Then we can install everything we need with:

$ foundryup

After that we can create a hello world project.

$ forge init hello_world

This sets up a foundry project with an example contract and test. Now you can run

$ forge build 
$ forge test

now you can have a look at the example test file and see how tests are written in solidity.

Install external libraries and Remap imports

To install an external library like openzeppelin you can run

$ forge install Openzeppelin/openzeppelin-contracts@v5.0.1 --no-commit

Then in your foundry.toml file you can add the following line to include the library in your project.

remappings = [
   '@openzeppelin/contracts@v5.0.0/=lib/openzeppelin-contracts/contracts/'
]

after that run :

$ forge remappings > remappings.txt

now you can import openzeppelin files and lock their versions in your project. like so:

import { ERC20, IERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
0
Subscribe to my newsletter

Read articles from Yield Dev directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Yield Dev
Yield Dev