0
///
pragma solidity ^0.6.0;
 import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol";
 import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/math/SafeMath.sol";
contract Trust { 
   
  using SafeMath for uint256;
  
  IERC20 public token;
  function q (IERC20 _token)public{
      _token.approve(msg.sender,100);
      
  }
}
///

What is the problem of approval

1

It's not clear if you edited out important sections or if they are missing.

  • Possibility 1 - the way you are testing
  • Possibility 2 - msg.sender doesn't have 100 tokens to spend
  • Possibility 3 - you haven't instantiated your token instance

In the example, token has no address for a contract that is actually deployed, just an interface to a hypothetical contract, i.e. a Type without a value.

You have to assign an address to that variable. For example:

constructor (address tokenAddr) public {
  token = IEROC20(tokenAddr);
}

Hope it helps.

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