Introduction

OpenZeppelin is an important and open-source organization in the blockchain, which provides useful features and services for developing, deploying, and managing smart contracts securely. It also provides an easier way for developers to make a decentralized application (dApps) on the blockchain platform Ethereum. It was founded in 2017.

OpenZeppelin

Key features of OpenZeppelin

Let's discuss some features of OpenZeppelin in the given below.

  1. Smart Contract Library: OpenZeppelin gives an inclusive library of smart contracts which used to address common patterns and functionalities of token standards (ERC20, ERC721), access control, upgradeability, etc.
  2. Security: It is an important feature of OpenZeppelin. In this feature, contracts are tested, audited, and reviewed by security experts. This reduces the risk of vulnerabilities and exploits in the deployed smart contracts.
  3. Upgradability: OpenZeppelin provides tools for creating perfect smart contracts, allowing developers to fix bugs, add features, or improve their contracts without disrupting the existing state or requiring a complete redeployment.
  4. Developer Tools: OpenZeppelin includes various tools and utilities to enhance the developer experience. These tools help with contract deployment, testing, and interacting with smart contracts on the blockchain.
  5. Community and Support: OpenZeppelin has a strong community of developers and users who contribute to the project, share knowledge, and provide support. This collaborative environment promotes continuous improvement and innovation.
  6. Documentation: The framework comes with extensive documentation, tutorials, and examples to help developers understand how to use the components and build secure (dApps) efficiently.

Let's see the main website of "OpenZeppelin" by clicking the link given below.

 Website

Visit to OpenZeppelin website: www.openzeppelin.com

OpenZeppelin Contracts wizard

The OpenZeppelin Contracts Wizard is an interactive tool designed to help developers create smart contracts easily. It allows users to build contracts by selecting from various components provided by the OpenZeppelin Contracts library.

Let's see the figure of Contracts Wizard on the main website of OpenZeppelin below.

 Contracts Wizard

Website Link: https://www.openzeppelin.com

Openzeppelin Contracts Wizard Library

There are mainly three types of contracts wizard libraries that are used by developers to build a decentralized application(dApps).

Library 1. ERC20

ERC20 is a type of technical method used for smart contracts on the Ethereum blockchain. It defines a common list of rules that an Ethereum token must implement, allowing developers to create compatible tokens that can be traded and managed easily.

Features of "ERC20" provided by OpenZeppelin Contracts Wizard.

Code Example

// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.20;

import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PermitUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20VotesUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20FlashMintUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

contract MyToken is Initializable, ERC20Upgradeable, ERC20BurnableUpgradeable, ERC20PausableUpgradeable, OwnableUpgradeable, ERC20PermitUpgradeable, ERC20VotesUpgradeable, ERC20FlashMintUpgradeable {
    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        _disableInitializers();
    }
    function initialize(address initialOwner) initializer public {
        __ERC20_init("MyToken", "MTK");
        __ERC20Burnable_init();
        __ERC20Pausable_init();
        __Ownable_init(initialOwner);
        __ERC20Permit_init("MyToken");
        __ERC20Votes_init();
        __ERC20FlashMint_init();
    }
    function pause() public onlyOwner {
        _pause();
    }
    function unpause() public onlyOwner {
        _unpause();
    }
    function mint(address to, uint256 amount) public onlyOwner {
        _mint(to, amount);
    }
    function clock() public view override returns (uint48) {
        return uint48(block.timestamp);
    }
    // solhint-disable-next-line func-name-mixedcase
    function CLOCK_MODE() public pure override returns (string memory) {
        return "mode=timestamp";
    }
    // The following functions are overrides required by Solidity.
    function _update(address from, address to, uint256 value)
        internal
        override(ERC20Upgradeable, ERC20PausableUpgradeable, ERC20VotesUpgradeable)
    {
        super._update(from, to, value);
    }
    function nonces(address owner)
        public
        view
        override(ERC20PermitUpgradeable, NoncesUpgradeable)
        returns (uint256)
    {
        return super.nonces(owner);
    }
}

Above the code has been created in the open Zeppelin contracts wizard used by its type "ERC20". And enables its several features, votes utilities, access control, and upgradeability like Mintable, Burnable, Pausable, Permit, Flash Minting, Timestamp, Ownable, Transparent. If you open this code then use " REMIX-Ethereum. IDE " to run the code.

Library 2. ERC721

ERC721 is a type of technique that is used for non-fungible Tokens in the Ethereum blockchain. Unlike ERC20 tokens, which are fungible and identical to each other, ERC721 tokens are unique and distinguishable from one another. It represented digital art, collectibles, and real estate.

Features of "ERC721" provided by OpenZeppelin Contracts Wizard.

Code Example

// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.20;

import "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721URIStorageUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721BurnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/cryptography/EIP712Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721VotesUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";

contract MyToken is Initializable, ERC721Upgradeable, ERC721EnumerableUpgradeable, ERC721URIStorageUpgradeable, ERC721PausableUpgradeable, AccessControlUpgradeable, ERC721BurnableUpgradeable, EIP712Upgradeable, ERC721VotesUpgradeable, UUPSUpgradeable {
    bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
    bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
    uint256 private _nextTokenId;
    bytes32 public constant UPGRADER_ROLE = keccak256("UPGRADER_ROLE");
    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        _disableInitializers();
    }
    function initialize(address defaultAdmin, address pauser, address minter, address upgrader)
        initializer public
    {
        __ERC721_init("MyToken", "MTK");
        __ERC721Enumerable_init();
        __ERC721URIStorage_init();
        __ERC721Pausable_init();
        __AccessControl_init();
        __ERC721Burnable_init();
        __EIP712_init("MyToken", "1");
        __ERC721Votes_init();
        __UUPSUpgradeable_init();
        _grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
        _grantRole(PAUSER_ROLE, pauser);
        _grantRole(MINTER_ROLE, minter);
        _grantRole(UPGRADER_ROLE, upgrader);
    }
    function pause() public onlyRole(PAUSER_ROLE) {
        _pause();
    }
    function unpause() public onlyRole(PAUSER_ROLE) {
        _unpause();
    }
    function safeMint(address to, string memory uri) public onlyRole(MINTER_ROLE) {
        uint256 tokenId = _nextTokenId++;
        _safeMint(to, tokenId);
        _setTokenURI(tokenId, uri);
    }
    function _authorizeUpgrade(address newImplementation)
        internal
        onlyRole(UPGRADER_ROLE)
        override
    {}
    // The following functions are overrides required by Solidity.
    function _update(address to, uint256 tokenId, address auth)
        internal
        override(ERC721Upgradeable, ERC721EnumerableUpgradeable, ERC721PausableUpgradeable, ERC721VotesUpgradeable)
        returns (address)
    {
        return super._update(to, tokenId, auth);
    }
    function _increaseBalance(address account, uint128 value)
        internal
        override(ERC721Upgradeable, ERC721EnumerableUpgradeable, ERC721VotesUpgradeable)
    {
        super._increaseBalance(account, value);
    }
    function tokenURI(uint256 tokenId)
        public
        view
        override(ERC721Upgradeable, ERC721URIStorageUpgradeable)
        returns (string memory)
    {
        return super.tokenURI(tokenId);
    }
    function supportsInterface(bytes4 interfaceId)
        public
        view
        override(ERC721Upgradeable, ERC721EnumerableUpgradeable, ERC721URIStorageUpgradeable, AccessControlUpgradeable)
        returns (bool)
    {
        return super.supportsInterface(interfaceId);
    }
}

Above the code has been generated in the open Zeppelin contracts wizard used by its type "ERC721". And enables several features, votes utilities, access control, and upgradeability like Mintable, Auto Increment Ids, Burnable, Pausable, Enumerable, URI Storage, Block Numbers, Roles, and UUPS. If you open this code then use " REMIX-Ethereum. IDE " to run the code.

Library 3. ERC1155

The ERC-1155 is a level of standard in smart contracts. ERC1155 is a multi-token standard that allows the creation and management of multiple types of tokens within a single contract. This implementation is designed to be modular, making it easy to extend and customize according to the needs of different projects.

Features of "ERC1155" provided by OpenZeppelin Contracts Wizard.

Code Example

// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.20;

import "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/manager/AccessManagedUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155BurnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155SupplyUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
contract MyToken is Initializable, ERC1155Upgradeable, AccessManagedUpgradeable, ERC1155PausableUpgradeable, ERC1155BurnableUpgradeable, ERC1155SupplyUpgradeable {
    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        _disableInitializers();
    }
    function initialize(address initialAuthority) initializer public {
        __ERC1155_init("");
        __AccessManaged_init(initialAuthority);
        __ERC1155Pausable_init();
        __ERC1155Burnable_init();
        __ERC1155Supply_init();
    }
    function setURI(string memory newuri) public restricted {
        _setURI(newuri);
    }
    function pause() public restricted {
        _pause();
    }
    function unpause() public restricted {
        _unpause();
    }
    function mint(address account, uint256 id, uint256 amount, bytes memory data) public restricted {
        _mint(account, id, amount, data);
    }
    function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) public restricted {
        _mintBatch(to, ids, amounts, data);
    }
    // The following functions are overrides required by Solidity.
    function _update(address from, address to, uint256[] memory ids, uint256[] memory values) internal override(ERC1155Upgradeable, ERC1155PausableUpgradeable, ERC1155SupplyUpgradeable) {
        super._update(from, to, ids, values);
    }
}

Above the code has been created in the open zeppelin contracts wizard used by its type "ERC1155". And enables its all several features, votes utilities, access control, and upgradeability like Mintable, Burnable, Supply Tracking, Pausable, Updatable URI, Managed, and Transparent. If you open this code then use " REMIX-Ethereum. IDE " to run the code.

Conclusion

OpenZeppelin plays a crucial role in advancing blockchain technology by providing tools and resources that make it easier and safer to develop decentralized applications. Their efforts contribute significantly to the overall security and accessibility of the blockchain ecosystem.