0

I am trying to transfer ERC20 token from another smart contract. For that I am following this article. So I wrote the smart contract as following,

pragma solidity >=0.4.23 <0.6.0;

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

contract SmartMatrix is IERC20 {
    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 I try to deploy,

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

But I remove interface It deploys successfully. For example, The following code works,

pragma solidity >=0.4.23 <0.6.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v2.5.0/contracts/token/ERC20/IERC20.sol";

contract SmartMatrix is IERC20 {
    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;
    }
}

Please help me to fix this issue.

Edited: Removed inheritance and tried as the following and getting same error,

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;
    }
}
2
  • Get rid of is IERC20. Dec 14, 2020 at 15:05
  • @goodvibration Thank you for responding. I tried removing is IERC20. but getting same error.
    – selva
    Dec 14, 2020 at 15:29

1 Answer 1

0

First of all remove the inheritance. Now replace your constructor with this one:

constructor(address token) public {
    _token = IERC20(token);
}

Now in the constructor you have to pass the address of the deployed IERC20 contract.

5
  • 1
    Thanks for responding. I did the following but getting same error, ` 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; } }`
    – selva
    Dec 14, 2020 at 15:53
  • Did you remove is IERC20? I told you, you don't need inheritance when dealing with interfaces. Dec 14, 2020 at 19:45
  • Example: streamable.com/jn9qt2 Dec 14, 2020 at 19:56
  • Yes I removed is IERC20. But still I am getting same error. And I have updated smart contract in the question after removing is IERC20. And the link [streamable.com/jn9qt2] is not working.
    – selva
    Dec 14, 2020 at 22:22
  • I've no idea what you're doing, but my code works. I'm deploying the contract with no errors, copy my code and try again pastebin.com/hTKU7SMv . I'm using Remix to deploy and complier version is 5.17. Dec 15, 2020 at 6:30

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.