Interface contact [solidity]

 Introduction to Interface

Interfaces can have only unimplemented functions. Also, they are neither compiled nor deployed. They are also called pure abstract contracts


  • Cannot implement any of their functions. All interface functions are implicitly virtual
  • Are defined with the keyword interface
  • Cannot inherit other contracts or interfaces (after solidity 6.0.0 interfaces can inherit from interfaces) but other contracts can inherit from interfaces
  • Function state mutability can be pure , view , payable or default(blank)
  • Fallback functions cannot be defined in an Interface
  • Interface functions are implicitly "virtual"
  • Cannot define a constructor
  • Functions can be defined external only
  • Cannot have state variables but local variables definition is allowed
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

interface ICounter {
    function count() external view returns (uint);

    function increment() external;
}

contract MyContract {
    function incrementCounter(address _counter) external {
        ICounter(_counter).increment();
    }

    function getCount(address _counter) external view returns (uint) {
        return ICounter(_counter).count();
    }
}

Comments