3

I'm trying create a simple NFT using Java Spring Boot with Web3J dependency. When I'm trying to generate the .abi file and .bin file using Solc compiler, I'm receiving this error:

Source "@openzeppelin/contracts/token/ERC721/ERC721.sol" not found: File not found. Searched the following locations: "".
 --> src/main/resources/solidity/nfts/SimpleCollectible.sol:7:1:
  |
7 | import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The message for this error is clear, I cannot import external file. How I could fix this without copying the required files into my project?

I am new in this topic and I want to integrate smart contracts with Java.

Aniruddh Parihar
  • 3,072
  • 3
  • 21
  • 39
Seby Galan
  • 31
  • 2

2 Answers2

1

I am also facing the same Error I found one solution for this, but it also has some issues. After compiling it give abi and bin files for both contracts.

You can try this, Add an openzeppelin file path also in your command.

Found solution here

solcjs ./node_modules/@openzeppelin/contracts/utils/math/SafeMath.sol 
       ./src/main/resources/solidity/AddressBook.sol  --bin --abi --optimize -o 
       ./src/main/resources/out 

-- The first path is the openzeppelin contract path and the second is the source file path.

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
0

Normally your ide might have an option similar to this in vscode Package Default Dependencies Contracts Directory. if this configured successfully, import statement should automatically go inside node_modules and find the @openzeppeling dependency. If not you have to pass relative path in solidity code:

 import "../node_modules/@openzeppelin/contracts/token/ERC721/ERC721.sol";
 
Yilmaz
  • 35,338
  • 10
  • 157
  • 202