LEARN SOLIDITY LESSON
Require Solidity. Inheritance Solidity. Import Solidity
Require Solidity
For that we use require. require makes it so that the function will throw an error and stop executing if some condition is not true
function sayHiToBean(string memory _name) public returns (string memory) {
// Compares if _name equals "Bean". Throws an error and exits if no require(keccak256(abi.encodePacked(_name)) == keccak256(abi.encodePacked("Bean"))); // If it's true, proceed with the function: return "Hi!"; }
Inheritance Solidity
This can be used for logical inheritance (such as with a subclass, a Cat is an Animal). But it can also be used simply for organizing your code by grouping similar logic together into different contracts.
contract Cat { function catchphrase() public returns (string memory) { return "So Wow CryptoCat"; } } contract BabyCat is Cat { function anotherCatchphrase() public returns (string memory) { return "Such Moon BabyCat"; } }
Import Solidity
When you have multiple files and you want to import one file into another, Solidity uses the import keyword:
pragma solidity >=0.5.0 <0.6.0;
import "./catHelp.sol"; contract CatFeeding is CatFactory { }
Comments