1

I have a "real" contract and an interface contract.

In the interface contract, I want only to expose the 'getter' functions of the "real" contract.

Those functions are implicitly generated by the Solidity compiler (solc).

The options, I suppose, are:

  1. external constant
  2. public constant
  3. external view
  4. public view

But no matter how I try it, the binary of my "real" contract comes out with no contents.

The only way I am able to work-around it is by explicitly implementing the 'getter' functions (in the "real" contract).

Since those functions can also be generated implicitly, I was hoping to avoid it, so I would like to know if by any chance I'm doing anything wrong in the way that I declare these functions in the interface contract.

Here is the interface contract ('ITest.sol'):

pragma solidity ^0.4.18;

contract ITest {
    function x() external constant returns (uint256);
}

And here is the "real" contract ('Test.sol'):

pragma solidity ^0.4.18;
import './ITest.sol';

contract Test is ITest {
    uint256 public x;

    function Test(uint256 _x) public {
        x  = _x;
    }
}

Thank you!!!

9
  • "... the binary of my 'real' contract comes out with no contents." Can you explain what you mean by that?
    – user19510
    Jan 14 '18 at 15:46
  • @smarx: An empty file. There's a description of a similar problem in this post. Jan 14 '18 at 15:59
  • Can you share the actual contract(s) you're compiling?
    – user19510
    Jan 14 '18 at 16:06
  • Is there a reason you don't just put uint256 public x in ITest?
    – user19510
    Jan 14 '18 at 16:32
  • Well, namely coding conventions. In most languages an interface consists of functions only, no variables. In any case, I'm pretty sure I have tried that approach too, and got the same results. Of course, one could argue that an interface is not needed here altogether, but I'm trying to stick to the general layout of my contracts, in which, for each "real" contract there's a corresponding interface contract, and any two "real" contracts "communicate" with each other only via interface contracts. Jan 14 '18 at 16:39

Your Answer

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

Browse other questions tagged or ask your own question.