Remix: ERC20: Can't call _mint - Undeclared identifier. Did you mean "mint"?

Hello, after some trouble with remix I'm back at a npm/truffle/ganache setup...

The reason why I tried out remix was:

DeclarationError: Undeclared identifier. Did you mean "mint"?
        _mint(to, amount);

And what can I say... stuck at the same place:

:computer: Environment

"truffle": {
"version": "5.1.57",
"resolved": "https://registry.npmjs.org/truffle/-/truffle-5.1.57.tgz",
      "integrity": "sha512-hash", //there is a real hash ... feels kind of unconfy sharing hashes without to      know for what they are
      "requires": {
        "app-module-path": "^2.2.0",
        "mocha": "8.1.2",
        "original-require": "1.0.1"
      }
    },
compilers: {
solc: {
  version: "0.7.0",    // Fetch exact version from solc-bin (default: truffle's version)
  docker: false,        // Use "0.5.1" you've installed locally with docker (default: false)
  settings: {          // See the solidity docs for advice about optimization and evmVersion
   optimizer: {
     enabled: false,
     runs: 200
   },
   evmVersion: "byzantium"
  }
}
  }
{
  "name": "participate",
  "version": "1.0.0",
  "description": "",
  "main": "truffle-config.js",
  "directories": {
    "test": "test"
  },
  "dependencies": {
    "@openzeppelin/contracts": "^3.3.0",
    "truffle": "^5.1.57",
    "zeppelin-solidity": "^1.12.0"
  },
  "devDependencies": {},
  "scripts": {
    "test": "mocha"
  },
  "author": "",
  "license": "ISC"
}
};

:memo:Details

"pre" is in this case another contract. When I use remix and import ERC20Detailed with a "normal" github path, then it works. Okay the other contract cant mint or burn, but at least I can do it and also set the pre address.

:1234: Code to reproduce

pragma solidity >=0.5.0 <0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";


contract Testyis IERC20, Ownable {
   using SafeMath for uint256;
   using SafeMath for uint8;
   
   address _owner;
   
   
...
   

constructor () public {
    _owner = address(msg.sender);
    _decimals = 18;

...
    
    function mint(address to, uint256 amount) public {
        require((pre == msg.sender), "Caller is not a minter");
        _mint(to, amount);
    }

	function burn(address from, uint256 amount) public {
        require((pre == msg.sender), "Caller is not a burner");
        _burn(from, amount);
    }
}

EDIT
Ok missunderstud ERC20 / IERC20 - but I would like to override ERC20 methodes and I get the error:

TypeError: Trying to override non-virtual function. Did you forget to add "virtual"?
function name() public view returns (string memory) {

Even when my openzeppelin is version 3.3.0 as you see..
But I guess thats another thread ...

1 Like

Hi @MToken,

You seem to have figured it out already, your mistake is in

It should be:

contract Testy is ERC20, Ownable {

Regarding your second question, our view functions are not virtual. (For more context see How we plan to adopt Solidity 0.6 virtual functions).

However, I don't think you need to override for what you're trying to do. You should use the constructor of ERC20 to define name and symbol:

contract Testy is ERC20, Ownable {
    constructor() ERC20("Name", "SYM") {}
}

Read more about the constructor in the docs.

2 Likes

Was a bad excample… I got the same error with every function… (for now I just want learn and try out how far I can go so yes the code maybe dont even make sense…)

CompileError: @openzeppelin/contracts/token/ERC20/ERC20.sol:96:5: TypeError: Trying to override non-virtual function. Did you forget to add "virtual"?
function totalSupply() public view override returns (uint256) {

1 Like

@MToken it’s hard to help based just on that error, could you show us your current code?

1 Like

Hi @MToken,

Were you able to resolve? Otherwise can you share your contract?