30: Interface
An interface in Solidity is a collection of function definitions that a contract can implement. An interface is a way for a contract to communicate with other contracts or with external applications.
Example 1 This is an example of a basic interface in Solidity:
This interface defines two functions: foo and bar. foo takes in a uint (unsigned integer) argument and returns a uint. Similarly, bar takes in a string argument and returns a bool.
Example 2 This is an example of an interface that uses modifiers:
In this example, we use a modifier
called onlyOwner
to ensure that foo can only be called by the contract's owner. The _ at the end of the modifier definition indicates that the function should proceed with the rest of its logic after the modifier has been executed.
That's it for the lesson 30! In the next lesson, Abstract
Last updated