Hallenjay
Sun, 24 Dec 2023 15:09:19 +0000
Smart Contracts

app.js:186 Error claiming tokens: Error: Transaction has been reverted by the EVM:
/**
*Submitted for verification at mumbai.polygonscan.com on 2023-12-02
*/

// 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 claim function is returning the error above and also return unable to estimate gas fee if call the claim function on polygon testnet, this is my javascirpt code : ` <> 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], maxFeePerGas: 2700000000 });
    console.log(receipt);
  }
} catch (error) {
  console.error("Error claiming tokens:", error);
}

}; </>` I deployed the contract using hardhat

2 posts - 1 participant