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?


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.

  • Thanks! Is it okay to create extended interfaces in the contract which doesn't use some functions? – Ivan Zakharov Feb 12 '19 at 13:15
  • No, you should have defined the function written in interface by the contract. – Rick Park Feb 12 '19 at 13:17
  • Even when I use interfaces only for interaction, without implementing them? – Ivan Zakharov Feb 12 '19 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 '19 at 14:19

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.