Can't call mint on ERCToken

I am getting this error:
Member "mint" not found or not visible after argument-dependent lookup in contract ERC20

Been staring at this for an hour. Would appreciate any help!

Thank you

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

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

contract stakingTest {

    ERC20 public token;
    ERC20 public token2;
    address private tokenAddress;
    uint private fixedAmount;

    constructor () {
    }

    function setToken(ERC20 _token) public {
        token = _token;
    }

    function setAddress(address _address) public {
        tokenAddress = _address;
        token2 = ERC20(_address);
     }

    // Error
    // Member "mint" not found or not visible after argument-dependent lookup in contract ERC20
    function claim() public {
        token._mint(msg.sender, fixedAmount);
    }

    // This works
    function totalSupply()  public view returns (uint) {
        return token.totalSupply();
    }

}

:1234: Code to reproduce


:computer: Environment

The _mint function is an internal function, meaning it can only be call from inside a ERC20 contract. You are trying to access the function from another contract, which could be done if _mint would be public or external. If you need your stakingTest contract to be able to call mint it should be an ERC20 contract:

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

contract stakingTest is ERC20 { //Like this
}
1 Like