Importing Contracts

Foundry is able to grab directly from github.

Example: You want to use the IERC20.sol interface provided by Yield at: https://github.com/yieldprotocol/yield-utils-v2/blob/main/contracts/token/IERC20.sol

Get dependencies

First we need to download the repo into our dependencies folder (lib):

forge install yieldprotocol/yield-utils-v2

Forge will install the repo into our project directory (repo can be found inside lib)

.gitmodules will be updated to reflect the dependencies:

Run forge remappings to check how forge is mapping out your dependencies

forge remappings

yield-utils-v2/ is mapped to directory lib/yield-utils-v2/contracts

This informs us how to craft our import statement.

Craft import statement

// points to lib/yield-utils-v2/contracts/token/IERC20.sol
import "yield-utils-v2/token/IERC20.sol";

Now when forge build is run, there should not be any issues.

Last updated