Transfer tokens to users on actions

I have 2 smart contracts. The first contract has some basic function for a ToDo list. So functions to add or delete tasks. The second contract is just a standard ERC20 contract with fixed cap of 100 mil tokens.

So I need a function to give the user that created/deleted a task 1 token. So every time the user uses the function addTask or deleteTask he will get automatically 1 token to his wallet address. Is this possible?
:computer: Environment

Remix, local server and Ganache

:memo:Details

:1234: Code to reproduce

solidity ^0.5.1;
contract Tasks{ 
     
// Defining a structure to  
// store a task 
struct Task 
{ 
  string task; 
  bool isDone; 
} 
  
mapping (address => Task[]) private Users; 
function addTask(string calldata _task) external 
{ 
  Users[msg.sender].push(Task({ 
    task:_task, 
    isDone:false
    })); 
} 

function deleteTask(uint256 _taskIndex) external 
{ 
  delete Users[msg.sender][_taskIndex]; 
} 
}
1 Like

Hi @Asaad1996,

Welcome to the community :wave:

When a user completes a task you could either transfer a token to them (the contract would need to hold tokens or have an allowance of tokens to transfer), or mint a token (within your set cap) to them (the contract would need to have rights to mint the token).

You could look at some of the concepts in crowdsales for token emission, contract holds tokens, contract mints tokens or contract has allowance for tokens: https://docs.openzeppelin.com/contracts/2.x/crowdsales#token-emission

I also suggest looking at: Points to consider when creating a fungible token (ERC20, ERC777)