6

I've imported the Open Zeppelin ERC721 token standard into my VS Code with the Solidity extension, but see the following warnings on all my OZ import statements:

Screenshot of error

Why is this happening and what is the workaround for this warning?

What I've tried:

  • change default workspace compiler to localNodeModule (began to throw other warnings like on the pragma solidity line)

Example of solution I've tried

jimmythecoder
  • 79
  • 1
  • 3

8 Answers8

7

Just install the Solidity+Hardhat Extension ,this will take care of the errror.

3

run below command

npm install @openzeppelin/contracts

Change the import line like this

 import "./node_modules/@openzeppelin/contracts/token/ERC721/ERC721.sol";        
Surya Ram
  • 41
  • 3
2

You could try this solution here, the only one that helped me. https://stackoverflow.com/a/72241149/7537543

When you compile programmatically using solc, new syntax was introduced, which you have to include in compile.js.

// New syntax (supported from 0.5.12, mandatory from 0.6.0)
var output = JSON.parse(
solc.compile(JSON.stringify(input), { import: findImports })
);

You should have a helper function for finding imports

function findImports(relativePath) {
//my imported sources are stored under the node_modules folder!
 const absolutePath = path.resolve(__dirname, 'node_modules',   relativePath);
 const source = fs.readFileSync(absolutePath, 'utf8');
 return { contents: source };
}
p0xcd556
  • 21
  • 2
0

Unfortunately I ran into this error too & just gave the path manually:

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

This solved my error. (I'm a linux user so path may differ for you)

Thanks ;-)

udi
  • 3,672
  • 2
  • 12
  • 33
0

you have to manually guide the open zepplin import to its source file if you have it downloaded in your node modules then all you have to do is to change its path like this " ../node_modules/" and also make sure to use the latest extension of juan blanco's solidity extension and solidity and hardhat extension and if you are following a tutorial your first lines of codes would probably be import "hardhat/console.sol"; all you have to do here is to manually direct only this file to its designated place and the others would do it by themselves.

0

What you have to do is:

If you have "Solidity by Juan Blanco" for Truffle and "Solidity by Nomic Foundation" for Hardhdat, and if you are using Hardhat, disable the one by Juan Blanco and just use the one by Nomic Foundation, it just worked for me. Screenshot

Make sure to create a Hardhat project (npx hardhat) and install: npm install --save-dev "hardhat@^2.12.7" "@nomicfoundation/hardhat-toolbox@^2.0.0"

npm i @openzeppelin/contracts

  • Please phrase this as an explained conditional answer, in order to avoid the impression of asking a clarification question instead of answering (for which a comment should be used instead of an answer, compare https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead ). For example like "If your problem is ... then the solution is to .... because .... ." – Yunnosch Feb 22 '23 at 07:45
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 05 '23 at 14:22
0

you can add following lines at beginning

import "C:\Users\{user_name}\AppData\Roaming\npm";

// so below is my code:
pragma solidity ^0.8.0;

import "C:\Users\Dell\AppData\Roaming\npm"; // you can add your {username} instead of Dell.
import "node_modules/@openzeppelin/contracts/utils/Counters.sol";
import "./node_modules/@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "./node_modules/@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
avariant
  • 2,234
  • 5
  • 25
  • 33
Bharat
  • 1
-5

Two things you have to do:

(1) Install the OZ library via npm install @openzeppelin/contracts

(2) If you see Error HH606 (i.e. project can't compile), it's likely because The Solidity version pragma statement in these files doesn't match any of the configured compilers in your config.. Ensure that your pragma version matches the version in your hardhat config.

E_net4
  • 27,810
  • 13
  • 101
  • 139
jimmythecoder
  • 79
  • 1
  • 3
  • Please do not call it a DUMB question. You can choose not to answer & move on. But kindly do not discourage people from posting their questions in the StackOverflow community. – dhanesh24g Sep 02 '23 at 10:23