0
contract Token is ERC20 {
constructor() public ERC20('DonkeyCoin', 'DKC'){
    _mint(msg.sender, uint(100 * 10 ** uint(decimals())));
}
// now we can make the approve for the msg.sender the amount it wants to share 
function Approve(uint amount) public {
    ERC20.approve(msg.sender, amount);
}

}

contract TransferToken{

IERC20 public  Token ;

constructor(IERC20 _Token){
    Token = _Token;
}
function transfer(address sender , address recipient , uint amount) public {
    Token.allowance(msg.sender, sender);
    Token.transferFrom(sender, recipient, amount);
}

}

I did everything but still getting error , please help

0

I assume you're getting error from your third function. Before calling it (TransferTokens) you need to call ERC20.approve() from the caller's address.

Your second function here doesn't help the third function. your second function is basically just approving another address to use its ERC20 balance, which doesn't make much sense, cuz the the contract itself is the "ERC20 Token Contract", you're suppose to have any tokens in that contract.

1
  • so what will be the best practice here .. in order to transfer the token ? Sep 22 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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