Error claiming tokens: Error: Transaction has been reverted by the EVM

I have a token contract and a airdrop contract, I am getting the above error if i try to call the claim function from the frontend and I get unable to estimate gas fee if i use the mumbai testnet toc all the claim function. , i dont know the required part of my contracts or code that i need to achieve result. I want anyone who connect wallets should be able to call the claim function while the function pick the declared claim amount from the contract and send it to the callers accoun.

MY AIRDROP CONTRACT CODE:

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

contract JayTechAirdrop {
    address public owner;
    address public jayTechTokenAddress;
    uint256 public claimAmount = 1e6 * 1e18; // 1 million JayTech tokens
    uint256 public gasFee;

    mapping(address => bool) public hasClaimed;

    event Claim(address indexed recipient, uint256 amount);
    event Withdrawal(address indexed owner, uint256 amount);

    modifier onlyOwner() {
        require(msg.sender == owner, "Not the owner");
        _;
    }

    constructor(address _jayTechToken, uint256 _gasFee) {
        owner = msg.sender;
        jayTechTokenAddress = _jayTechToken;
        gasFee = _gasFee;
    }

    function claim() external {
        require(!hasClaimed[msg.sender], "Already claimed");

        // Call the internal transfer function
        _transfer(jayTechTokenAddress, msg.sender, claimAmount);
        hasClaimed[msg.sender] = true;

        emit Claim(msg.sender, claimAmount);
    }

    function withdrawGasFee() external onlyOwner {
        uint256 balance = address(this).balance;
        require(balance >= gasFee, "Insufficient balance");

        payable(owner).transfer(gasFee);

        emit Withdrawal(owner, gasFee);
    }

    // Fallback function to receive Ether (gas fee)
    receive() external payable {}

    // Internal ERC-20 transfer function
    function _transfer(address token, address to, uint256 amount) internal {
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, amount));
        require(success && (data.length == 0 || abi.decode(data, (bool))), "Transfer failed");
    }

    // Allow anyone who deploys the contract to call the withdraw function
    function withdraw(uint256 amount) external onlyOwner {
        _transfer(jayTechTokenAddress, owner, amount);
    }
}

MY FRONT END CALL FUNCTION:

      const hasClaimed = await airdropContract.methods
        .hasClaimed(accounts[0])
        .call();

      if (hasClaimed) {
        console.log("Wallet has already claimed tokens.");
      } else {
        console.log("Calling claim function...");

        // Example code to connect and claim tokens
        const receipt = await airdropContract.methods
          .claim() // Replace _jayTechToken and _gasFee with actual values
          .send({ from: accounts[0], gas: 500000 });
        console.log(receipt);
      }
    } catch (error) {
      console.error("Error claiming tokens:", error);
    }
  };

THE ERROR I GOT FROM THE CONSOLE AFTER THE FUNCTION IS CALLED:

app.js:186  Error claiming tokens: Error: Transaction has been reverted by the EVM:
{
  "blockHash": "0x90462b3bfec3d08d95198e6afc7d9a750fed77155b9ba621b513cec286595e5c",
  "blockNumber": 43954934,
  "contractAddress": null,
  "cumulativeGasUsed": 195257,
  "effectiveGasPrice": 2500000015,
  "from": "0x48a6e2c8b2589a1f8b9afb3b009ab0b6a09a5ad8",
  "gasUsed": 35034,
  "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000008000000000000000000000000000000000000010000080000000000000800000000000000000000100000000004000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000080000000000000000000200000000000000000000000000000000000000000000000000000000000004000000000000000000001000000000000000000000000000000100040000000000000000000000000000000000000000000000000000000000000000000100000",
  "status": false,
  "to": "0x56da83886ace0305c9b8eb035f4c5ce2fbe7fb36",
  "transactionHash": "0xe51b40326e654acfb5858b8b6801da10136f03d6eb75e1317bd6f93368caf225",
  "transactionIndex": 1,
  "type": "0x2",
  "events": {
    "0": {
      "address": "0x0000000000000000000000000000000000001010",
      "blockNumber": 43954934,
      "transactionHash": "0xe51b40326e654acfb5858b8b6801da10136f03d6eb75e1317bd6f93368caf225",
      "transactionIndex": 1,
      "blockHash": "0x90462b3bfec3d08d95198e6afc7d9a750fed77155b9ba621b513cec286595e5c",
      "logIndex": 10,
      "removed": false,
      "id": "log_92930b73",
      "returnValues": {},
      "signature": null,
      "raw": {
        "data": "0x00000000000000000000000000000000000000000000000000004fa878d00a00000000000000000000000000000000000000000000000000056c89a250890e040000000000000000000000000000000000000000000035a0123e03268c36a835000000000000000000000000000000000000000000000000056c39f9d7b904040000000000000000000000000000000000000000000035a0123e52cf0506b235",
        "topics": [
          "0x4dfe1bbbcf077ddc3e01291eea2d5c70c2b422b415d95645b9adcfd678cb1d63",
          "0x0000000000000000000000000000000000000000000000000000000000001010",
          "0x00000000000000000000000048a6e2c8b2589a1f8b9afb3b009ab0b6a09a5ad8",
          "0x000000000000000000000000be188d6641e8b680743a4815dfa0f6208038960f"
        ]
      }
    }
  }
}
    at Object.TransactionError (errors.js:87:21)
    at Object.TransactionRevertedWithoutReasonError (errors.js:98:21)
    at index.js:396:57
    at h (regeneratorRuntime.js:72:17)
    at Generator._invoke (regeneratorRuntime.js:55:24)
    at Generator.next (regeneratorRuntime.js:97:21)
    at n (asyncToGenerator.js:3:20)
    at s (asyncToGenerator.js:22:9)
    at asyncToGenerator.js:27:7
    at new Promise (<anonymous>)

MY TOKEN CODE which allows only the creator alone to call the transfer function, now i transfer some tokens to the contract but the claim function still return error on all fronts, I dpeloyed the token using hardhat

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

contract JayTech {
    string public name = "Jaytech Token";
    string public symbol = "JAYT";
    uint256 public totalSupply = 99900000000 * 10**18; // 1 trillion tokens
    address public owner;

   
    mapping(address => uint256) public balanceOf;

    event Transfer(address indexed from, address indexed to, uint256 value);

    constructor() {
        owner = msg.sender;
        balanceOf[msg.sender] = totalSupply;
        emit Transfer(address(0), msg.sender, totalSupply);
    }

    function transfer(address to, uint256 value) external returns (bool) {
        require(balanceOf[msg.sender] >= value, "Insufficient balance");
        balanceOf[msg.sender] -= value;
        balanceOf[to] += value;
        emit Transfer(msg.sender, to, value);
        return true;
    }
}

:computer: Environment

Hello @Hallenjay

When trying to read a balance from your token, I am getting an Error
Error: Invalid JSON RPC response: ""

I think you should look into that. My recommandation here would be to use an existing ERC20 implementation, that would include transferFrom & approval (which will be extremely usefull to your users).

I would also recommand you test your code, either in hardhat or in remix, before deploying it to any public chain.

Which is extremely weird, since the contract is verified and the balanceOf function is permission-less.

This feels more like a problem in mumbai.polygonscan than a problem in the contract.