5

I'm writing smart contract using Foundry. When I try to import contract from github like this:

import "@openzeppelin/contracts/token/ERC20/IERC20";

I will see error like this:

Source "@openzeppelin/contracts/token/ERC20/IERC20" not found: File import callback not supported

I think I have done the necessary things in which I have added the package like this:

forge install Openzeppelin/openzeppelin-contracts

and written remappings in foundry.toml file.

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

But i still see the error. How can I fix the error?

2 Answers 2

3

Try changing taking out the second. “Contracts” on the right side of the remapping

If you are using VS Code, add this to .vscode in your project root like :

{ "solidity.packageDefaultDependenciesContractsDirectory": "src", 
"solidity.packageDefaultDependenciesDirectory": "lib",
 "solidity.compileUsingRemoteVersion": "v0.8.15", 
"solidity.remappings": [ "forge-std/=lib/forge-std/src/", 
                     "@openzeppelin/=lib/openzeppelin-contracts/",] 
} 
3
  • This works as in i can compile the files, but i still can see the error.
    – normies
    Commented Jul 5, 2022 at 15:58
  • Is this error in vscode and not in the terminal? IF yes , add this to .vscode in your project root like : ``` { "solidity.packageDefaultDependenciesContractsDirectory": "src", "solidity.packageDefaultDependenciesDirectory": "lib", "solidity.compileUsingRemoteVersion": "v0.8.15", "solidity.remappings": [ "forge-std/=lib/forge-std/src/", "@openzeppelin/=lib/openzeppelin-contracts/", ] } ```
    – 0xsegfault
    Commented Jul 5, 2022 at 16:27
  • You also need to configure Remapping as this answer mentioned ethereum.stackexchange.com/a/135181/65057
    – Peter
    Commented Mar 11 at 4:12
0

The remapping has to be in a remapping.txt file, not in the foundry.toml

After after adding

@openzeppelin/=lib/openzeppelin-contracts/

to this remamping.txt the error should be gone.


see: https://book.getfoundry.sh/projects/dependencies

"You can customize these remappings by creating a remappings.txt file in the root of your project."

1
  • remapping.txt was the original was of adding remapping. You can still do it this way, but most folks just add it to their foundry.toml. Its easier to reason about the whole project's configuration from one place.
    – 0xsegfault
    Commented Sep 17, 2022 at 13:10

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.