ParserError: Source "@openzeppelin/contracts/token/ERC20/ERC20.sol" not found: File import callback not supported

Hello.

Just starting out trying to learn contracts and how they work. Found an example from your wizard and ran it fine in remix, compiled and deployed fine. When I went to etherscan.io to compile the code I received this error :

........
Error! Unable to generate Contract ByteCode and ABI (General Exception, unable to get compiled [bytecode])
........

The Compiler Warning(s) game me this :
........
ParserError: Source "@openzeppelin/contracts/token/ERC20/ERC20.sol" not found: File import callback not supported
--> myc:8:1:
|
8 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
........

I am not 100% sure what is going on with this error, have googled it and found that the @open statement is supposed to be used but that did not help as shown in code below. I did however notice in MyContract_metadata.json the "version": "0.5.17+commit.d19bba13" is show, do not know if this would have to be changed to the ^0.8.2 version or if it matters?

Any help would be greatly appreciated for your time.
Thank you.

:1234: Code to reproduce

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.2;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract CoreToken is ERC20 {
    constructor() ERC20("Core Token", "CMN") {
        _mint(msg.sender, 1000000000 * 10 ** decimals());
    }
}

:computer: Environment

Used the wizard to create the contract here on OpenZeppelin
Used remix solidity ^0.8.2

1 Like

"https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol" not found: File import callback not supported

you should create a folder named contracts and inside have a folder named token, and inside the folder token you should leav a ERC20 smartcontract, you can found one on the git of openzeppelin

Hi, welcome! :wave:

Thanks for using Wizard and enjoying it!
It seems like you are trying to verify the contract, I think you can have a look at this tutorial:

1 Like

Refer to the method in this link:https://stackoverflow.com/questions/65969531/cant-import-openzeppelin-node-modules-file-import-callback-not-supported

Hello . I get the same error above like You. Where and How can I install the openzeppelin folders so that "import" function in the code can work , not give error and verify the contract successfully ?

Any help would be greatly appreciated .
Thanks a lot.

In your project folder, create a file named package.json with the following contents:

{
    "devDependencies": {
        "@openzeppelin/contracts": "4.9.2"
    }
}

Open a terminal, navigate to the path of that file, and enter either one of the following:

  • npm install
  • yarn install

Thank You very much.

By "in your project folder" , do you mean in remix.ethereum.org screen ? I have compiled it , deployed it and want to verify .

Where and How can I access to the project folder in my computer ?

No, I did not mean in the Remix folder, I thought you had a problem building your project in general.
If your contract is already deployed and you're just looking to verify it on Etherscan via Remix, then you just need to flatten the source code before you paste it into Remix.

Thank You . How can i flatten my code before i paste it into the etherscan's place on the "verify and publish " page ?

Replace every import statement in your code with the contents of the file being imported.

I could verify now.
I have right clicked on Remix page to the .sol file and clicked on "flatten"
Copy and paste to the verify and publish page . It worked.

Thank You for your help

1 Like