'Solidity - Check balance of a user address using openzeppelin

I'm using Truffle and upgradable Openzeppelin contracts. I have two contracts.

Token.sol:

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

import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

contract MyToken is Initializable, ERC20Upgradeable {
    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() initializer {}

    function initialize() initializer public {
        __ERC20_init("MyToken", "MTK");

        _mint(msg.sender, 10000000 * 10 ** decimals());
    }
}

AnotherContract.sol:

pragma solidity ^0.8.2;
import "./IAnotherContract.sol";

contract AnotherContract is IAnotherContract {
  function doSomethingIfBalanceIsEnough()
    external
    returns (string memory)
  {
    // ... 
  }
}

How do I check how many MTK tokens a user has? I need to check it in doSomethingIfBalanceIsEnough function.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source