Having some problems with the approval of a transaction with an ERC20

We are developing a smart contract hooked to github users in order to give them some recompenses.
The trouble occurs when we are trying to do a transfer from a wallet minted with all the tokens to a user wallet.

We received an error that we were missing an 'approve' so we try with:

  • Call the _approve and approve with 3 or 2 parameters.
  • Call the _approve with owner and spender being the minted address.
  • Call the _approve with owner being the minted address and spender being msg.sender.
  • Call the _approve and transferFrom with this without this

Our code is:

function rewardUser(string memory githubUser, GithubActions actionType) public returns(bool success) {
        require(usersAddress[githubUser] != address(0), "Address not registered");
        require(actionType >= GithubActions.issue_comment && actionType <= GithubActions.pull_request_review_comment, "Wrong action");

        if(actionType == GithubActions.issue_comment) {
            _approve(MINTED_ADDRESS, msg.sender, REWARD_ISSUE_COMMENT);
            transferFrom(MINTED_ADDRESS, usersAddress[githubUser], REWARD_ISSUE_COMMENT);
            emit RewardIssueComment(usersAddress[githubUser]);
        else if(actionType == GithubActions.pull_request_review) {
            _approve(MINTED_ADDRESS, msg.sender, REWARD_PULL_REQUEST_REVIEW);
            transferFrom(MINTED_ADDRESS, usersAddress[githubUser], REWARD_PULL_REQUEST_REVIEW);
            emit RewardPullRequestReview(usersAddress[githubUser]);
        else if(actionType == GithubActions.pull_request_review_comment) {
            transferFrom(MINTED_ADDRESS, usersAddress[githubUser], REWARD_PULL_REQUEST_REVIEW_COMMENT);
            emit RewardPullRequestReviewComment(usersAddress[githubUser]);

        return true;

Now we are having this problem:

Gas Estimation Execution Reverted (ERC20: transfer amount exceeds allowance)

We are using @openzepellin/contracts and hardhat.
We are using only the ERC.20 contract

Sorry for the late reply.

Honestly, I'm confused, because I think the code you shared should work.

However, something different you can try is to use the internal _transfer function instead of _approve+transferFrom.

Let us know if you figured it out.