OpenZeppelin Part 5 There's More!

There's More!

OpenZeppelin has a wide range of utilities to help add more complexity to your contracts.

Cryptography

Within the cryptography folder are two contracts to help with security:

pragma solidity ^0.5.2;

import "openzeppelin-solidity/contracts/cryptography/ECDSA.sol";

contract ECDSAMock {
    using ECDSA for bytes32;

    function recover(bytes32 hash, bytes memory signature) public pure returns (address) {
        return hash.recover(signature);
    }

    function toEthSignedMessageHash(bytes32 hash) public pure returns (bytes32) {
        return hash.toEthSignedMessageHash();
    }
}

Read more in the documentation.

Drafts

The drafts folder contains contracts which are in their development stage.

Introspection

Introspection is a set of contracts that perform interface detection. They allow you to determine if your contract will support the interface you want to use.

Earlier in the series we introduced token standards. In this tutorial, we are going to talk about another standard called ERC165. ERC165 maintains run time interface detection. The introspection folder provides the following contracts:

pragma solidity ^0.5.2;

import "openzeppelin-solidity/contracts/introspection/ERC165.sol";

contract ERC165Mock is ERC165 {
    function registerInterface(bytes4 interfaceId) public {
        _registerInterface(interfaceId);
    }
}

Read more in the documentation.

Note: When we refer to the interface, we are talking about what the contracts Application Binary Interface (ABI) can represent. The ABI is the interface by which the application program gains access to the operating system and other services.

Lifecycle

Lifecycle contains a single contract called Pausable.sol which allows child contracts to have an emergency stop feature.

Math

pragma solidity ^0.5.2;

import "openzeppelin-solidity/contracts/math/SafeMath.sol";

contract SafeMathMock {
    function mul(uint256 a, uint256 b) public pure returns (uint256) {
        return SafeMath.mul(a, b);
    }

    function div(uint256 a, uint256 b) public pure returns (uint256) {
        return SafeMath.div(a, b);
    }

    function sub(uint256 a, uint256 b) public pure returns (uint256) {
        return SafeMath.sub(a, b);
    }

    function add(uint256 a, uint256 b) public pure returns (uint256) {
        return SafeMath.add(a, b);
    }

    function mod(uint256 a, uint256 b) public pure returns (uint256) {
        return SafeMath.mod(a, b);
    }
}

Read more in the documentation.

Payment

Payment allows you to set different properties in regards to payment options.

pragma solidity ^0.5.2;

import "openzeppelin-solidity/contracts/payment/PullPayment.sol";

contract PullPaymentMock is PullPayment {
    constructor () public payable {
    }

    function callTransfer(address dest, uint256 amount) public {
        _asyncTransfer(dest, amount);
    }
}

Read more in the documentation.

Utilities

Utilities contains contracts that don't fall under the other categories.

pragma solidity ^0.5.2;

import "openzeppelin-solidity/contracts/utils/Address.sol";

contract AddressImpl {
    function isContract(address account) external view returns (bool) {
        return Address.isContract(account);
    }
}

Read more in the documentation.

Next Steps

OpenZeppelin provides the user with a multitude of contracts to support the creation of complex contracts.