0

I want to create a contract to give the players rewards and they claim their rewards.

It seems everything is ok!

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

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

contract Rewards is Ownable {
    IERC20 public rewardsToken;

    mapping(address => uint) public rewards;

    constructor(address _rewardsToken) {
        rewardsToken = IERC20(_rewardsToken);
    }

    function setReward(address account,uint256 amount)  public onlyOwner  {
        rewards[account] = amount;
    }

    function claimReward() public{
        uint256 reward = rewards[msg.sender];
        rewards[msg.sender] = 0;
        rewardsToken.transfer(msg.sender, reward*10**18);
    }
}

but I don't know why when I claim the reward nothing happens and I have this errors.

enter image description here

I have enough ERC20 tokens

enter image description here

1
  • Does the contract have enough balance in the ERC20 token contract?
    – pbsh
    Jan 23, 2022 at 8:01

1 Answer 1

0

oh Boy, I forgot to send the tokens to my contract! that's why It didn't work!

enter image description here

so after I send the tokens It worked correctly

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.