简体   繁体   中英

Web3J | Source "@openzeppelin/contracts/token/ERC721/ERC721.sol" not found: File not found

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.

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.

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";
 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM