Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

solidity
communitycreator

What is Solidity interface?

Chinweuba Elijah Azubuike

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

What is an interface?

Interfaces can be seen as pure abstract contracts.

Key points about solidity interface

  • Functions can not be implemented.
  • Interfaces can be inherited.
  • External functions must be defined for all stated functions.
  • Constructors can not be declared, state variables can’t also be declared.

Example code

pragma solidity ^0.5.0;
interface Multiply {
function getOutput() external view returns(uint);
}
contract sample is Multiply {
function getOutput() external view returns(uint){
uint x = 12;
uint y = 10;
uint multval = x * y;
return multval;
}
}
Solidity Interface

Explanation

  • Lines 3 to 5: We instantiated our multiply interface.

  • Line 6: We created a contracted and implemented the created interface.

  • Line 7: We are utilizing the getOutput() function.

  • Lines 8 to 9: We are declaring and defining variables.

  • Line 10: We carry out the logic for multiplication and equate it to multval variable

  • Line 11: We return the multiplied value.

RELATED TAGS

solidity
communitycreator

CONTRIBUTOR

Chinweuba Elijah Azubuike

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring