@0xcert/ethereum-xcert 中文文档教程

发布于 6年前 浏览 30 项目主页 更新于 3年前

构建状态 NPM 版本 依赖状态 Bug Bounty

Xcert 令牌实施对于以太坊区块链。

这是以太坊区块链的 Xcert 令牌的官方实施。 这是一个使用 Truffle 框架构建的开源项目。

此实施的目的是为任何想要在以太坊区块链上使用和开发 0xcert 协议低级层的人提供一个良好的起点。 您可以使用经过多次审核的这段代码,而不是自己重新实现 0xcert 规范,我们希望它会在未来被社区广泛使用。

Xcert 是 ERC-721 实现的扩展。 它是一种固执己见的不可替代令牌,带有数字资产证明并支持额外的 0xcert 协议功能。 您可以在官方 0xcert 协议黄皮书 中阅读更多相关信息。

Structure

由于这是一个 Truffle 项目,您将在 contracts/tokens/ 中找到所有代币 目录。 有多种实现方式,您可以选择:

  • Xcert.sol: This is the base Xcert token implementation.
  • BurnableXcert.sol: This implements optional support for token burning. It is useful if you want token owners to be able to burn them.
  • MutableXcert.sol: This implements enables token data to be changed by authorized address.
  • PausableXcert.sol: This implements optional freeze for token transfers. It is useful if you want to be able to pause all token transfers at any time.
  • RevokableXcert.sol: This implements optional revoking mechanism. It is useful if you want to allow owner of the Xcert contract to revoke any token at any time.

Installation

要求:

  • NodeJS 9.0+ recommended.
  • Windows, Linux or Mac OS X.

NPM

这是一个 NPM 模块,用于 Truffle 框架。 为了在您的 Javascript 项目中使用它作为依赖项,您必须首先通过 npm 命令安装它:

$ npm install @0xcert/ethereum-xcert

Source

克隆存储库并安装所需的 npm 依赖项:

$ git clone git@github.com:0xcert/ethereum-xcert.git
$ cd ethereum-xcert
$ npm install

确保一切都已正确设置:

$ npm run test

所有测试都应该通过。

Usage

NPM

要在 JavaScript 代码中与包的合约进行交互,您只需需要该包的 .json 文件:

const contract = require("@0xcert/ethereum-xcert/build/contracts/Xcert.json");
console.log(contract);

Source

最简单的开始方法是在 contracts/tokens/ 下创建一个新文件(例如 MyXcertToken.sol):

pragma solidity ^0.4.23;

import "../tokens/BurnableXcert.sol";

contract MyXcertToken is BurnableXcert {

  constructor(
    string _name,
    string _symbol,
    bytes4 _conventionId
  )
    public
  {
    nftName = _name;
    nftSymbol = _symbol;
    nftConventionId = _conventionId;
  }

}

就是这样。 让我们编译合约:

$ npm run compile

在本地部署它并开始与合约交互(铸造和转移代币)的最简单方法是使用 甘那许。 按照 此处 描述的 Truffle 文档中的步骤进行操作。

Contributing

请参阅 CONTRIBUTING.md 了解如何提供帮助。

Licence

有关详细信息,请参阅许可证

Build Status NPM Version Dependencies Status Bug Bounty

Xcert token implementation for the Ethereum blockchain.

This is the official implementation of the Xcert token for the Ethereum blockchain. This is an open source project build with Truffle framework.

Purpose of this implemetation is to provide a good starting point for anyone who wants to use and develop the low-level layer of the 0xcert protocol on the Ethereum blockchain. Instead of re-implementing the 0xcert specs yourself you can use this code which has gone through multiple audits and we hope it will be extensively used by the community in the future.

An Xcert is an extension of the ERC-721 implementation. It is an opinionated non-fungible token which carries a proof of a digital asset and supports additional 0xcert protocol features. You can read more about this in the official 0xcert protocol yellow paper.

Structure

Since this is a Truffle project, you will find all tokens in contracts/tokens/ directory. There are multiple implementations and you can select between:

  • Xcert.sol: This is the base Xcert token implementation.
  • BurnableXcert.sol: This implements optional support for token burning. It is useful if you want token owners to be able to burn them.
  • MutableXcert.sol: This implements enables token data to be changed by authorized address.
  • PausableXcert.sol: This implements optional freeze for token transfers. It is useful if you want to be able to pause all token transfers at any time.
  • RevokableXcert.sol: This implements optional revoking mechanism. It is useful if you want to allow owner of the Xcert contract to revoke any token at any time.

Installation

Requirements:

  • NodeJS 9.0+ recommended.
  • Windows, Linux or Mac OS X.

NPM

This is an NPM module for Truffle framework. In order to use it as a dependency in your Javascript project, you must first install it through the npm command:

$ npm install @0xcert/ethereum-xcert

Source

Clone the repository and install the required npm dependencies:

$ git clone git@github.com:0xcert/ethereum-xcert.git
$ cd ethereum-xcert
$ npm install

Make sure that everything has been set up correctly:

$ npm run test

All tests should pass.

Usage

NPM

To interact with package's contracts within JavaScript code, you simply need to require that package's .json files:

const contract = require("@0xcert/ethereum-xcert/build/contracts/Xcert.json");
console.log(contract);

Source

The easiest way to start is to create a new file under contracts/tokens/ (e.g. MyXcertToken.sol):

pragma solidity ^0.4.23;

import "../tokens/BurnableXcert.sol";

contract MyXcertToken is BurnableXcert {

  constructor(
    string _name,
    string _symbol,
    bytes4 _conventionId
  )
    public
  {
    nftName = _name;
    nftSymbol = _symbol;
    nftConventionId = _conventionId;
  }

}

That's it. Let's compile the contract:

$ npm run compile

The easiest way to deploy it locally and start interacting with the contract (minting and transferring tokens) is to deploy it on your personal (local) blockchain using Ganache. Follow the steps in the Truffle documentation which are described here.

Contributing

See CONTRIBUTING.md for how to help out.

Licence

See LICENSE for details.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文