简体   繁体   English

Web3J | 找不到源“@openzeppelin/contracts/token/ERC721/ERC721.sol”:找不到文件

[英]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.我正在尝试使用 Java Spring Boot 和 Web3J 依赖项创建一个简单的 NFT。 When I'm trying to generate the .abi file and .bin file using Solc compiler, I'm receiving this error:当我尝试使用 Solc 编译器生成.abi文件和.bin文件时,我收到此错误:

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.我是这个主题的新手,我想将智能合约与 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.编译后为两个合约提供 abi 和 bin 文件。

you can try this, Add an openzeppelin file path also in your command.你可以试试这个,在你的命令中添加一个 openzeppelin 文件路径。

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 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. -- 第一个路径是openzeppelin合约路径,第二个是源文件路径。

Normally your ide might have an option similar to this in vscode Package Default Dependencies Contracts Directory .通常,您的 ide 在 vscode Package Default Dependencies Contracts Directory中可能具有与此类似的选项。 if this configured successfully, import statement should automatically go inside node_modules and find the @openzeppeling dependency.如果此配置成功,导入语句应自动 go 在node_modules并找到@openzeppeling依赖项。 If not you have to pass relative path in solidity code:如果不是,您必须在solidity代码中传递相对路径:

 import "../node_modules/@openzeppelin/contracts/token/ERC721/ERC721.sol";
 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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