0

I am learning Solidity and I am using Remix to experiment and enhance my learning. I am currently trying to create a simple contract that uses an Interface.

pragma solidity ^0.4.19;

contract InterfaceWithMe {

    function call() returns (string);

}

contract Interfacing {

    address ckAddress = 0x9fe1c58215407d67719ba680360940056e5eceb7;
    InterfaceWithMe daContract = InterfaceWithMe(ckAddress);

    function call() returns (string) {
        return daContract.call();
    }

When I try an compile this on Remix, I get the following type error on line 14:

TypeError:Return argument type inaccessible dynamic type is not implicitely convertibel to expected type (type of first return variable) string memory.

Here is the other contract that I use to interface with this contract:

pragma solidity ^0.4.19;

contract InterfaceWithMe {

    function call() returns (string) {
        return "Hello";
    }
}

Thanks for the help.

1

1 Answer 1

1

A fair bit of fiddling for readability and style.

pragma solidity 0.4.25;

contract Interface {
    function call() public pure returns (string);
    function isInterface() public pure returns(bool);
}

contract Interfacing {

    Interface daContract; 

    constructor(address theContract) public {
        daContract = Interface(theContract);
        require(daContract.isInterface());
    }

    function call() public view returns (string) {
        return daContract.call();
    }

}

contract InterfaceWithMe is Interface {

    function call() public pure returns (string) {
        return "Hello";
    }

    function isInterface() public pure returns(bool) {
        return true;
    }
}

Here it is in Remix to show it working.

  1. Deploy InterfaceWithMe
  2. Copy the deployed address to the clipboard.
  3. Deploy Interfacing passing the address from the clipboard into the constructor.
  4. Call call in `Interfacing.
  5. Hello

enter image description here

Hope it helps.

3
  • Thank you for your response! I have some follow up questions for you. Why does InterfaceWithMe need to inherit from Interface? Shouldn't Interfacing inherit from Interface? Nov 6, 2018 at 0:17
  • It's about when to use composition and when to use inheritance. Camry is Car so it must implement all the standard inherited functions. Driver starts Car so that will cast and instance of something as a type Car and then invoke it with myCar.start (). Note that the compiler can see the source code to work out the interface. Nov 6, 2018 at 8:03
  • Why contract Interfacing existence. Is necessary that bridge ti implement the interface? Thx Feb 11, 2019 at 11:38

Your Answer

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

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