Discussion: How to mint GameToken the "proper" way

Ivan or Filip mentioned this slightly in the course but I would like to know the solution (or walkaround).

The problem with the current contract is that literally anyone can mint the token without needing to play the game.

contract GameToken is ERC20 {
    string memory _name,
    string memory _symbol
  ) ERC20(_name, _symbol) {


  function mint(address _to, uint256 _value) external returns(bool){
    _mint(_to, _value);
    return true;

I would like to know how to make it so that the user only gets (mint) the token when he/she actually played the game.

One solution is to make the mint function callable only by the owner. However, the owner will have to constantly monitor the game, and the owner will have to pay the gas to transfer the token to the user.

Any idea on how to mint GameToken properly?

Sorry for tagging but do you have any idea / thoughts about this?

Hey @REGO350, sorry for the delay.

I could suggest to use some kind of mapping on who has played the game, then you could do a require or a modifier that check that condition.


// to manage claiming, only 1 time a msg.sender can claim tokens
    mapping(address => bool) hasPlayedGame;

You might need an extra function that the user will have to trigger to change its status on the mapping.

Carlos Z

1 Like