ERC-20 – How to Troubleshoot Issues When Transferring ERC-20 Tokens from a Contract

erc-20transfer

pragma solidity ^0.6.2;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";


contract MyContract {  
    IERC20  LINK;
 
    constructor(address token) public {
             LINK = IERC20(token);
    }
    
    function transfertip(address to_, uint256 amount_) public {
       
        LINK.transfer( to_, amount_);
    }
}

I was able to compile and deploy the contract,but when I try to call transfer function on remix , it throws gas estimation error

Best Answer

That's because the contract does not have enough LINK. You have to pre-fund it with at least an amount_ number of tokens if you want to be able to call LINK.transfer inside it.

You can transfer tokens to the smart contract by using any Ethereum wallet, e.g. MetaMask.

Related Topic