Using ERC20 transferFrom on Remix

I tried the same logic. But I remove the import statement as import not working while deploying smart contract. (verify and publish step)

    pragma solidity >=0.4.23 <0.6.0;

    interface IERC20 {

        function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
    }

    contract SmartMatrix {
        IERC20 private _token;
        constructor(IERC20 token) public {
            _token = token;
        }
        function sendERC20TokeToDnividends(address sender, address recipient, uint256 amount) public returns (bool) {    
            _token.transferFrom(sender, recipient, amount);
            return true;
        }
    }

But I am getting the following error while deploying with remix. Help me to fix this issue.

This contract may be abstract, not implement an abstract parent's methods completely or not invoke an inherited contract's constructor correctly.

1 Like

Hi @selv,

Welcome to the community :wave:

When we use an ERC20 token with another contract (and this contract calls transferFrom), we first need to approve an allowance for the contract.

See: Example on how to use ERC20 token in another contract.

Can you give a bit more detail about what you are trying to do?

@abcoathup Thanks for your response. I tried same link (Example on how to use ERC20 token in another contract) which you have provided. Your example works fine without issue. I have deployed my own smart contract (I have added below) into ethereum using remix IDE. When I try to verify and publish, it is not allowing import statement. So I removed import statement and replaced with IERC20 interface.

    interface IERC20 {
        function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
    }

Because we need only transferFrom function, I removed rest of them. Now I tried to compile it in remix. It compiled successfully. But When I try to deploy it, it says the following information in pop-up window of remix IDE.
This contract may be abstract, not implement an abstract parent's methods completely or not invoke an inherited contract's constructor correctly.

The following is the smart I tried to deploy,

    pragma solidity >=0.4.23 <0.6.0;

    interface IERC20 {

        function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
    }

    contract SmartMatrix {
        IERC20 private _token;
        constructor(address token) public {
            _token = IERC20(token);
        }
        function sendERC20TokeToDnividends(address sender, address recipient, uint256 amount) public returns (bool) {    
            _token.transferFrom(sender, recipient, amount);
            return true;
        }
    }
1 Like

Hi @selv,

We can import OpenZeppelin Contracts via GitHub for Remix.
See: Deploy a simple ERC20 token in Remix.

I deployed an ERC20 token (from: Deploy a simple ERC20 token in Remix). I was then able to deploy your contract in Remix and after approving an allowance from a token holder account, I was able to call sendERC20TokeToDnividends.

I compiled the SmartMatrix contract with Solidity 0.5.17.

The pop-up error is if you were inheriting from an interface or an abstract contract and hadn’t implemented all the functions. Was this from your ERC20 token rather than Smart Matrix contract?

@abcoathup Thank you very much. I wrongly tried to deploy interface from Remix popup.

1 Like