Solidity

Solidity Interfaces

Solidity Interfaces Main Tips

  • Interfaces in Solidity are similar to abstract contracts, but the main difference is that they cannot have their functions implemented.
  • Interfaces can be inherited.

Solidity Interfaces

Interfaces in Solidity are a lot like abstract contracts, except that their functions cannot be implemented.

Additionally, there are other restrictions:

  1. Cannot inherit contracts and other interfaces.
  2. Some of these restrictions might be lifted in the future.
  3. Cannot define enums.
  4. Cannt define structs.
  5. Cannot define variables.
  6. Cannot define constructors.
  7. Interfaces are limited to what can be represented by the Contract ABI, and additionally, the conversion from the ABI and to an Interface and vice versa supposedly would be possible without any information being lost.

A specific keyword is used to denote interfaces:

Example

pragma solidity ^0.4.11;

interface TokenContract {
    function transferEth(address recipientAddress, uint amountSum);
}

 

Try on Remix Try live on Hosting

Contracts are allowed to inherit interfaces from other contracts.

 

Read previous post:
Solidity Abstract Contracts

Solidity Abstract Contracts Main Tips Some contracts cannot be compiled themselves because their functions lack implementation, but can be used...

Close