0

I have one interface like the following:

pragma solidity ^0.4.11;
interface TokenInterface {
    function transfer(address recipient, uint amount) external returns(bool);
}

And the implementation in another contract:

pragma solidity ^0.4.11;
import "./TokenInterface.sol";
contract TokenImpl {
    function transfer(address recipient, uint amount) public returns(bool)
    {
         return true;
    }
}

The problem is that if I change to the following the code. Remix don´t tell me nothing related to. The method not correspond to the interface.

pragma solidity ^0.4.11;
import "./TokenInterface.sol";
contract TokenImpl {
    function transfer(address recipient, uint amount) public returns(bytes32)
    {
         return "true";
    }
}

Just with the import tag the Impl is applying the Interface structure??

I´m not doing the interface call in the rigth way??

I have to add a constructo qith the address of the Interface?? (But a interface can´t deploy)

I´m a lit confused

1

Just with the import tag the Impl is applying the Interface structure??

No. The source code is loaded. You could use it for several things but you're not using it at all.

I´m not doing the interface call in the right way?

No. Your TokenImpl is an implementation of TokenInterface.

contract TokenImpl is TokenInterface {

Do so, and the compiler will alert you that your implementation doesn't match the interface.

I have to add a constructo qith the address of the Interface?? (But a interface can´t deploy)

No need. You're right, it won't deploy so a constructor would be a wrong step in the wrong direction.

Hope it helps.

  • I add the "is TokenInterface" and I made changes. But Remix dont warn my about a change. Im a lit confuse – UnexpectedCharacter Feb 11 at 14:55
  • 1
    Think of the interface as a minimum commitment. The implementation contract can do other things but it must implement the functions described in the interface or it will undefined functions and therefore will not deploy. – Rob Hitchens - B9lab Feb 11 at 15:42
  • Thankyou for the explanation Rob – UnexpectedCharacter Feb 12 at 7:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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