Commit a739f28d authored by Chris's avatar Chris
Browse files

Solidity completed Errors and Checks

parent ba380127
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -226,12 +226,20 @@ uint256 costOfNFT = 0.05 ether;

## Part 8

errors and checks

### Part 8 video link

<https://www.youtube.com/watch?v=P1J0HeQINcM&list=PLvfQp12V0hS2PQd9-X-E2AjmXj1o05WOo&index=8>

### Part 8 related .sol files

- [MyErrorsAndChecks.sol](./contracts/MyErrorsAndChecks.sol)

### Part 8 notes

- covers `require()`, `revert()`, `assert`

## Part 9

### Part 9 video link
+30 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

contract MyErrorsAndChecks {

    uint256 public maxAmount = 100;

    function updateMax() public {
        maxAmount = 50;
    }

    function myFunc(uint256 _x, uint256 _y) public view returns (uint256 xy) {
        require(_x > _y, "_x must be greater than _y."); // only if this is true, then the rest of the code will execute
        checkMax();
        return _x + _y;
    }

    function myPureRevertFunc(uint256 _x, uint256 _y) public pure returns (uint256 xy) {
        // logic
        if (_x == 10) {
            revert("_x should NEVER be 10.");
        }
        return _x + _y;
    }

    function checkMax() internal view {
        assert(maxAmount == 100);
    }
}