GithubHelp home page GithubHelp logo

nventuro / openzeppelin-contracts-ethereum-package Goto Github PK

View Code? Open in Web Editor NEW

This project forked from openzeppelin/openzeppelin-contracts-upgradeable

0.0 1.0 0.0 8.83 MB

Ethereum Package for the OpenZeppelin Contracts library.

Home Page: https://openzeppelin.com/contracts

License: MIT License

JavaScript 53.10% Solidity 45.96% Shell 0.94%

openzeppelin-contracts-ethereum-package's Introduction

OpenZeppelin

OpenZeppelin Contracts Ethereum Package

NPM Package Build Status

OpenZeppelin Contracts is a library for secure smart contract development. It provides implementations of standards like ERC20 and ERC721 which you can deploy as-is or extend to suit your needs, as well as Solidity components to build custom contracts and more complex decentralized systems.

This fork of OpenZeppelin is set up as a reusable Ethereum Package. It is deployed to the kovan, rinkeby, and ropsten test networks, as well as to the main Ethereum network. You can reuse any of the pre-deployed on-chain contracts by simply linking to them using the OpenZeppelin SDK, or reuse their Solidity source code as with the vanilla version of OpenZeppelin Contracts.

Differences with openzeppelin-contracts

This package contains the same contracts as the vanilla openzeppelin-contracts. The main difference is that all contracts in this package are potentially upgradeable: you will notice that no contracts have constructors defined, but use initializer functions instead. Also, this package is set up as an Ethereum package, and provides a small set of pre-deployed logic contracts that can be used directly via the OpenZeppelin SDK, without needing to deploy them again.

All in all, you should use this package instead of openzeppelin-solidity if you are managing your project via the OpenZeppelin CLI.

Install

npm install @openzeppelin/contracts-ethereum-package

Deployed logic contracts

  • StandaloneERC20: ERC20 token implementation, optionally mintable and pausable.
  • StandaloneERC721: ERC721 non-fungible token implementation with metadata and enumerable extensions, optionally mintable and pausable.
  • TokenVesting: tToken holder contract that can release its token balance gradually like a typical vesting scheme, with a cliff and vesting period, optionally revocable.
  • PaymentSplitter: Splits payments among a group of addresses proportionately to some number of shares they own.

Using via the OpenZeppelin CLI

You can easily create upgradeable instances of any of the logic contracts listed above using the OpenZeppelin CLI. This will rely on the pre-deployed instances in mainnet, kovan, ropsten, or rinkeby, greatly reducing your gas deployment costs. To do this, just create a new OpenZeppelin SDK project and link to this package.

$ npm install -g @openzeppelin/cli
$ openzeppelin init
$ openzeppelin link @openzeppelin/contracts-ethereum-package
> Installing...
$ openzeppelin create @openzeppelin/contracts-ethereum-package/StandaloneERC20
> Creating...

To create an instance of a contract, use the openzeppelin create command. As an example, you can run the following to create an upgradeable ERC20 named MyToken, with symbol TKN and 8 decimals, and an initial supply of 100 tokens assigned to the address HOLDER, with a MINTER and a PAUSER. Remember to replace $HOLDER, $MINTER, and $PAUSER with actual addresses when you run this command; you can specify more than one (or none at all) minters and pausers.

$ openzeppelin create
? Pick a contract to instantiate: @openzeppelin/contracts-ethereum-package/StandaloneERC20
? Pick a network: development
✓ Deploying @openzeppelin/contracts-ethereum-package dependency to network
? Do you want to call a function on the instance after creating it?: Yes
? Select which function: * initialize(name: string, symbol: string, decimals: uint8, initialSupply: uint256, initialHolder: address, minters: address[], pausers: address[])
? name (string): MyToken
? symbol (string): MYT
? decimals (uint8): 18
? initialSupply (uint256): 100e18
? initialHolder (address): 0x90f8bf6a479f320ead074411a4b0e7944ea8c9c1
? minters (address[]):
? pausers (address[]):
✓ Setting everything up to create contract instances
✓ Instance created at 0x2612Af3A521c2df9EAF28422Ca335b04AdF3ac66

OpenZeppelin will create an upgradeable ERC20 instance and keep track of its address in the .openzeppelin/rinkeby.json file. Should you update your version of the openzeppelin contracts ethereum package later down the road, you can simply run openzeppelin update to upgrade all your ERC20 instances to the latest version.

You can also deploy a ERC721 token by choosing the StandaloneERC721 contract when running openzeppelin create. Refer to the initialize function of each of the predeployed logic contracts to see which parameters are required for initialization.

Extending contracts

If you prefer to write your custom contracts, import the ones from this package and extend them through inheritance. Note that you must use this package and not @openzeppelin/contracts if you are writing upgradeable contracts.

pragma solidity ^0.5.0;

import '@openzeppelin/upgrades/contracts/Initializable.sol';
import '@openzeppelin/contracts-ethereum-package/contracts/token/ERC721/ERC721Full.sol';
import '@openzeppelin/contracts-ethereum-package/contracts/token/ERC721/ERC721Mintable.sol';

contract MyNFT is Initializable, ERC721Full, ERC721Mintable {
  function initialize() public initializer {
    ERC721.initialize();
    ERC721Enumerable.initialize();
    ERC721Metadata.initialize("MyNFT", "MNFT");
    ERC721Mintable.initialize(msg.sender);
  }
}

On our site you will find a few guides to learn about the different parts of OpenZeppelin, as well as documentation for the API. Keep in mind that the API docs are work in progress, and don’t hesitate to ask questions in our forum.

Security

OpenZeppelin Contracts is maintained by OpenZeppelin the company, and developed following our high standards for code quality and security. OpenZeppelin Contracts is meant to provide tested and community-audited code, but please use common sense when doing anything that deals with real money! We take no responsibility for your implementation decisions and any security problems you might experience.

The core development principles and strategies that OpenZeppelin Contracts is based on include: security in depth, simple and modular code, clarity-driven naming conventions, comprehensive unit testing, pre-and-post-condition sanity checks, code consistency, and regular audits.

The latest audit was done on October 2018 on version 2.0.0.

Please report any security issues you find to [email protected].

Contribute

OpenZeppelin exists thanks to its contributors. There are many ways you can participate and help build high quality software. Check out the contribution guide!

License

OpenZeppelin is released under the MIT License.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.