0

I'm trying to write a smart contract that can send ERC20 / ERC677 tokens from one user to another. For example send LINK from one address to another. I deployed my contract on the kovan network but it is not working.

Im using these addresses: 1)0xC2BD595E642889Fd8130A2eA57Cb820Eb7F66D60 2)0x6BbD26ae05Ac2C69532D2c679CB693F01FD6F49f Address: 0xC2BD595E642889Fd8130A2eA57Cb820Eb7F66D60 has 100 test LINK.

When I call transferToken(0xC2BD595E642889Fd8130A2eA57Cb820Eb7F66D60,0x6BbD26ae05Ac2C69532D2c679CB693F01FD6F49f,1) I get an error "false Transaction mined but execution" and the tokens are not transferred.

The transaction can be found at ( https://kovan.etherscan.io/tx/0x36752d523894e395feabee55c0f13cb02ef92684c5ec4383d77c94a41f1709e7p ).

I'm using remix btw.

What am i doing wrong?

This is my contract:

pragma solidity >=0.4.22 <0.7.0;

import "LinkInterfacee.sol";
contract Test{
    
  //kovan contract of chainlink token
   address linkAdr = 0xa36085F69e2889c224210F603D836748e7dC0088;

    IERC20 link = IERC20(linkAdr);    

    
    function transferToken(address sender, address recipient, uint256 amount) external payable returns(string memory){
        link.approve(address(this),amount);
        link.transferFrom(sender, recipient, amount);
    }
    

    function getBalanceOf(address _address)public view returns(uint256){
        return link.balanceOf(_address);
    }
    
    
}


4
  • Is import "LinkInterfacee.sol"; correct? Are you looking for transfer instead of transferFrom? Commented Dec 6, 2020 at 17:58
  • Yes, cause I can call getBalanceOf() Commented Dec 6, 2020 at 18:08
  • Could you please turn your code into a minimal reproducible code? Right now there is a lot going on. Commented Dec 6, 2020 at 19:43
  • @PatrickCollins my bad, I edited my question. Your help would be much appreciated Commented Dec 7, 2020 at 8:36

1 Answer 1

1

The issue is that you are using approve using the address(this). This means that address(this) is giving permission to link to transfer amount of link tokens to itself, address(this). This is wrong. The user who is calling transferToken function should give approve to your contract first, then call the transferToken function which could only transfer link from sender to recipient.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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