Index

Solidity

  1. types
  2. External
  3. Library
    1. self in Library
    2. using * for
    3. self example
  4. interfaces
  5. import
  6. msg.value
  7. Handling ether
  8. Erc20 token in contract
  9. assembly
  10. Enum
  11. memory, storage, calldata
  12. Array Pushing
  13. length in array
  14. Struct array
  15. mapping
  16. bytes and string
  17. uint to bytes32
  18. returns with name
  19. score voting
  20. Tests
    1. Async Tests
    2. Hooks

interfaces

Interfaces cannot have any functions implemented.

There are further restrictions:
• They cannot inherit other contracts or interfaces.
• All declared functions must be external.
• They cannot declare a constructor.
• They cannot declare state variables.



Interfaces are denoted by their own keyword:
pragma solidity >=0.5.0 <0.7.0;

interface Token {
    enum TokenType { Fungible, NonFungible }
    struct Coin { string obverse; string reverse; }
    function transfer(address recipient, uint amount) external;
}



What is the use of a interface or function without implementation?

Take, for example, this code. The interface contains function without implementation, so how it's useful.
pragma solidity ^0.5.0;

interface Calculator {
   function getResult() external view returns(uint);
}
contract Test is Calculator {
   constructor() public {}
   function getResult() external view returns(uint){
      uint a = 1
      uint b = 2;
      uint result = a + b;
      return result;
   }
}


How does this code working is different from the first one? What are the benefits of using an interface or function without implementation?

pragma solidity ^0.5.0;

contract Test {
   constructor() public {}
   function getResult() external view returns(uint){
      uint a = 1
      uint b = 2;
      uint result = a + b;
      return result;
   }
}