7

I was trying to follow this video https://www.youtube.com/watch?v=fNMfMxGxeag and at 5:23 when he goes on to edit remappings - I have no "remappings" in foundry.tml. When I try to just put there what he put and run forge build i get:

The application panicked (crashed).

and

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.
Aborted (core dumped)

how can I make it work?

3 Answers 3

4

You need to add remapping to a separate remappings.txt file instead of foundry.toml. (Seems like the instructions in video is a bit outdated). Try to follow the instructions in https://w.mirror.xyz/mOUlpgkWA178HNUW7xR20TdbGRV6dMid7uChqxf9Z58

3

foundry.toml

For using npm/nodejs as your dependency manager, this is the correct remapping for your foundry.toml file:

[profile.default]
remappings = [
    "@openzeppelin/contracts=node_modules/@openzeppelin/contracts/"
]

forge install

To use forge install please note that the correct method to install is:

Edit: As of April 2024, forge by default checks the latest git tag and uses that reference to install.

forge install openzeppelin/openzeppelin-contracts

This creates the following entry int .gitmodules file:

$ cat .gitmodules
[submodule "lib/openzeppelin-contracts"]
    path = lib/openzeppelin-contracts
    url = https://github.com/openzeppelin/openzeppelin-contracts

This points to the correct github repo and will install under the lib sub directory

You do not need a separate remappings.txt file, this is an artifact for keeping compatibility with dapptools

Supporting git submodules without forge

For git submodules you can not identify a git tag or hash explicitly in the .gitmodules file: only a branch name. However, you can basically do this to lock a specific tag/hash: cd into that submodule, then check out the tag or hash; commit.

[submodule "lib/openzeppelin-contracts"]
    path = lib/openzeppelin-contracts
    url = https://github.com/openzeppelin/openzeppelin-contracts
    branch = master

Handling a specific commit for git submodules[^1]

Make sure the parent repo knows that its submodule now tracks a branch:

$ cd /path/to/your/parent/repo
$ git add path/to/your/submodule
$ git commit -m "Make submodule tracking a branch"

Make sure the parent repo knows that its submodule now tracks a branch:

$ cd /path/to/your/parent/repo
$  git config -f .gitmodules submodule.<path>.branch <branch>

[^1]: source: https://stackoverflow.com/a/18799234/17258010

2
  • can you specify a version? What happens if breaking changes are introduced in the future?
    – nullsteph
    Mar 3 at 20:36
  • @nullsteph you can specify a version, using a git tag. However, I would refer to the specific Git commit of the corresponding git tag version, this is to ensure no issues with using git submodules outside of forge. As of April 2024, forge by default checks the latest git tag and uses that reference to install. E.g: bash $ forge install openzeppelin/openzeppelin-contracts uses git tag v5.0.2 (as of April 23, 2024) which was published: console Date: Thu Feb 29 17:44:22 2024 +0100 Release v5.0.2 (#4928)
    – Sam Bacha
    Apr 23 at 11:53
1

I followed the video, and this is working fine for me. Here is my foundry.toml

[profile.default]
src = 'src'
out = 'out'
libs = ['lib']

# See more config options https://github.com/foundry-rs/foundry/tree/master/config

remappings = ["@openzeppelin/=lib/openzeppelin-contracts/"]
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.