OpenZeppelin Part 1 Introductory

Introductory To OpenZeppelin

What Is OpenZeppelin?

OpenZeppelin is a library of reusable smart contracts to use with Ethereum and other EVM and eWASM blockchains. The contracts focus on secure and simple open source code. They are continuously tested and community reviewed to ensure they follow the best industry standards and security practices. As a developer it's difficult to create any piece of code from scratch; especially a contract. Through the use of OpenZeppelin's inheritable contracts, you have a base to start from and build complex features with little to, or no effort.

OpenZeppelin vs ZeppelinOS

Zeppelin solutions provides two different frameworks that are often confused to be the same thing. OpenZeppelin is a series of open source contracts to inherit into your code. In contrast, ZeppelinOS is a platform of utilities to securely manage your smart contracts. Ideally you use them together. In this tutorial series, we focus on OpenZeppelin.

Types of Contracts

OpenZeppelin has a variety of contracts to meet your needs divided into the following categories:

  1. Access: Roles and privileges.
  2. Crowdsale: Creating a smart contract for use in a crowdsale.
  3. Cryptography: Protecting your information.
  4. Drafts: Contracts that are currently in testing by the OpenZeppelin team.
  5. Introspection: Interface support.
  6. Lifecycle: Managing the behaviour of your contract.
  7. Math: Perform operations without overflow errors.
  8. Ownership: Manage ownership throughout your contract.
  9. Payment: How your contract releases tokens.
  10. Tokens: Creating tokens and protecting them.
  11. Utilities: Other contracts to assist you.

You inherit or combine OpenZeppelin contracts with your own contracts, serving as a base for you to build from. Later in the series, we will explore the uses of each of these contracts.

How To Download

To begin, you need to have Node.js and Truffle installed on your machine. To work with OpenZeppelin you should be familiar with Solidity, the programming language for smart contracts. The "Remix IDE - Your first smart contract" article is a good place to start.

In a directory of your choice make a new project folder and initialize Truffle in it.

mkdir myproject
cd myproject
truffle init

Now install the OpenZeppelin library into your projects root directory. Use the --save-exact option to ensure that all dependencies configure with an exact version, since breaking changes (change in software that can potentially make other components fail) might occur when versions are updated.

npm init -y
npm install --save-exact openzeppelin-solidity

OpenZeppelin is now installed. The library of contracts are stored in the node___modules/openzeppelin-solidity/contracts folder path within your project.

To use the library, add an import statement at the beginning of the contract specifying which one you want to use.

import "openzeppelin-solidity/contracts/ownership/Ownable.sol";

Conclusion

OpenZeppelin allows you to write more complex and secure contracts using their variety of base contracts. Less time spent building the foundation and more time to optimize details.

Documentation and Next Steps: