0

I have two contracts. One of them inherits another. Inside the parent contract I have the interface

interface Token {
    function transfer(address to, uint256 value) external returns (bool);
}

I want to override one inside the child contract to

interface Token {
    function transfer(address to, uint256 value) external returns (bool);
    function balanceOf(address who) external view returns (uint256);
}

But compiler shows DeclarationError: Identifier already declared.

Is there a way to override an interface?

1 Answer 1

1

Any interface can be, by definition, overridden by any real function having that same ABI, but it is not permitted to have N interfaces identical for some member (which precendece in override is not easy defined by inheritance graph!)

In other word if you want to have one interface for the first function, it is not needed to repeat that function identical in a new interface: just collect the other functions required and leave the first interface as is.

4
  • Thanks! Is it okay to create extended interfaces in the contract which doesn't use some functions? Feb 12, 2019 at 13:15
  • No, you should have defined the function written in interface by the contract.
    – Rick Park
    Feb 12, 2019 at 13:17
  • Even when I use interfaces only for interaction, without implementing them? Feb 12, 2019 at 13:24
  • Of course no. In that a case (outbound calls) the methods are implemented somewhere for you and you want to interact with them only. It’s ok.
    – Rick Park
    Feb 12, 2019 at 14:19

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.