Mr Coder
Mr Coder

Reputation: 847

use TransferFrom in solidity smartcontract ( ERC-20 )

I Need to Write a Smart Contract, In This Smart Contract User Can Send Token to Each Account in ERC-20 Network.

sender :0x5C2879Ec550e2F65D557b540B7DEAB3A6d478d62

recipient : 0xB643992c9fBcb1Cb06b6C9eb278b2ac35e6a2711

token Address : 0xa36085F69e2889c224210F603D836748e7dC0088

Kovan Testnet

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";

contract DexB is ERC20("KiaDex","DEX") {

   function SendTokenFromAddress(address token,address sender,address recipient,uint256 amount)
    external {

        IERC20 token = IERC20(token);
        token.allowance(sender,address(token));
        token.approve(sender,amount);
        require(token.balanceOf(sender) >=amount , "your balance is low" ) ;
        token.transferFrom(sender,recipient, amount);
        
    }
}

when i want to send token from this address 0x5C2879Ec550e2F65D557b540B7DEAB3A6d478d62 to this address 0xB643992c9fBcb1Cb06b6C9eb278b2ac35e6a2711 it dose not work and show me this message and afte that show not success transaction :

enter image description here

**whats the problem ? how can i sene Token from User Address to User Address in solidity ? **

Upvotes: 0

Views: 1254

Answers (1)

r42
r42

Reputation: 146

The sender, which in your case is 0x5C2879Ec550e2F65D557b540B7DEAB3A6d478d62 needs to approve the wallet address that's calling the sendTokenFromAddress function. The contract cannot do that on behalf of the account that needs to send tokens.

Upvotes: 1

Related Questions