0

I can't build my smart contract using Foundry because my dependency isn't recognized.

According to the documentation I have run the command

forge install openzeppelin/openzeppelin-contracts

Then I added the following line in the remapping.txt file:

openzeppelin-contracts/=lib/openzeppelin/contracts/

After updating the remapping file I ran the command and below are the results: forge remappings

enter image description here

Now when I create my simple ERC20 contract that has the following code:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract Grape is ERC20, Ownable {
    constructor() ERC20("Grape", "GRP") {
        _mint(msg.sender, 1000000 * 10 ** decimals());
    }
function mint(address to, uint256 amount) public onlyOwner {
        _mint(to, amount);
    }
}

And I try to build my project using: forge build

It doesn't build correctly: enter image description here

Mabel Oza
  • 557
  • 8
  • 22

2 Answers2

3

Foundry remapping file name should be "remappings.txt" not "remapping.txt"

And add @openzeppelin/=lib/openzeppelin-contracts/ to remappings.txt.

exd0tpy
  • 31
  • 3
-2

When installing openzeppelin contracts use

npm install @openzeppelin/contracts

After installing youll have node_modules folder. And as i presume you have contracts in src folder, so to connect openzeppelin contracts you should put correct path for every single file you import, like this:

import "../node_modules/@openzeppelin/contracts/access/Ownable.sol";