3

I keep getting this error, would be really cool to get help. I've heard that I need to install a program, forgot which but I'm not so sure that's a great idea to start with and is not the fix to this issue. I've tried to verify the contract but been without results.

Here's the issue:

: ParserError: Source "@openzeppelin/contracts/token/ERC20/ERC20.sol" not found: File import callback not supported
 --> myc:4:1:
  |
4 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

And this is my code (took away the name for security reasons):

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

contract secret is ERC20 {
    constructor(uint256 initialsupply) public ERC20 ("secret", "secret") {
        _mint(msg.sender, initialSupply);
    }
}
2
  • What tool are you using to compile the contract? Hardhat, Web3j, Truffle, ... The error says it is trying to open a file with "@openzeppelin/contracts/..." and it can't find it.
    – Ismael
    Nov 27, 2021 at 3:12
  • Someone told me to install openzeppelin into the contract and that's how far I am right now. And about tools, As far I know I'm doing a smart contract from remix.ethereum and a tool I would think is namely web3 but I'm not sure. I'm pretty much thinking it is. What advice would you have for me right now? This step has been a problem for me, so going through this would both help me and be a knowledge opportunity. Would be cool @Ismael if you could advise me on what to do next to solve this. Much thankful.
    – Feynman
    Nov 27, 2021 at 16:32

2 Answers 2

1

Try using

import "OpenZeppelin/[email protected]/contracts/token/ERC20/ERC20.sol";

'@' is not required anymore you can specify the same in your .yaml files(remappings).

0

To import an OpenZepplin contract from Remix you have to import using the full github URL.

For example to import contracts from v4.4.0 this will work.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.4.0/contracts/token/ERC20/ERC20.sol";


contract MyToken is ERC20 {
    constructor(uint256 initialSupply) ERC20("NOMNOM", "MON") {
        _mint(msg.sender, initialSupply);
    }
}
6
  • Thank you for the comment. Yes, I did that: I have deployed it and it's same as yours and even made it to an exchange, the only problem I have now is getting it verified and I keep getting this problem: File import callback not supported pragma solidity ^0.8.0; import "github.com/OpenZeppelin/openzeppelin-contracts/blob/master/…"; contract Mooncoin is ERC20 { constructor(uint256 initialsupply) public ERC20 ("secret", "secret") { _mint(msg.sender, initialsupply); } } What initiative should I do now, I'm very much confused.
    – Feynman
    Nov 27, 2021 at 17:40
  • As for the environment, probably a tool, it's injected web 3, I have used. Is there a special command or initiative I should take to verify the smart contract? As I said before I'm very much thankful for your help @Ismael.
    – Feynman
    Nov 27, 2021 at 17:44
  • @Feynman Remix has a plugin for verification on Etherscan if that doesn't work you should try asking a new question.
    – Ismael
    Nov 27, 2021 at 20:17
  • Cheers for the help again. But this token is on the bscscan and not etherscan @Ismael.
    – Feynman
    Nov 27, 2021 at 20:35
  • 1
    About import -> Don’t import from master , choose a tag @Feynman
    – Majd TL
    Nov 28, 2021 at 19:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.