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

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


!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
此软件包已移至 @nibbstack/erc721
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!



ERC-721 Token — Reference Implementation

这是ERC-721非-以太坊和 Wanchain 区块链的可替代令牌标准。 它还与其他 EVM 兼容链兼容,如币安智能链 (BSC)、Avalanche (AVAX) 等。这是一个开源项目,包含 Hardhat< /a> 测试。

此实施的目的是为任何想要在以太坊和 Wanchain 区块链上使用和开发不可替代代币的人提供一个良好的起点。 您可以使用经过多次审核的代码,而不是自己重新实现 ERC-721,我们希望它能在未来被社区广泛使用。 请注意,此实现比 ERC-721 标准更具限制性,因为它不支持开箱即用的 payable 函数调用。 但是,您可以自行添加。

如果您正在寻找功能更丰富、更先进的 ERC721 实施,请查看 0xcert Framework

Structure

所有合同和测试都在 src 文件夹中。 有多种实现,您可以选择:

  • nf-token.sol: This is the base ERC-721 token implementation (with support for ERC-165).
  • nf-token-metadata.sol: This implements optional ERC-721 metadata features for the token contract. It implements a token name, a symbol and a distinct URI pointing to a publicly exposed ERC-721 JSON metadata file.
  • nf-token-enumerable.sol: This implements optional ERC-721 support for enumeration. It is useful if you want to know the total supply of tokens, to query a token by index, etc.

tokensutils 目录中的其他文件名为 erc*.sol 的是接口并定义了各自的标准。

mocks 文件夹中提供了显示基本合同用法的模拟合同。

还可以在此处 看到测试模拟。 这些专门用于测试不同的边缘情况和行为,不应用作实施参考。

Requirements

  • NodeJS 12+ is supported
  • Windows, Linux or macOS

Installation

npm

如果你想在你的 JavaScript 项目中使用这个包,这是推荐的安装方法。

这个项目是 作为 npm 模块发布。 您必须使用 npm 命令安装它:

$ npm install @0xcert/ethereum-erc721@2.0.0

Source

如果您想改进 0xcert/ethereum-erc721 项目,这是推荐的安装方法。

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

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

确保一切都已正确设置:

$ npm run test

Usage

npm

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

const contract = require("@0xcert/ethereum-erc721/build/nf-token-enumerable.json");
console.log(contract);

Remix IDE (Ethereum only)

您可以使用 Remix IDE 使用此库快速部署合约。 这是一个例子。

你已经创造并拥有独特的玻璃吹制艺术品(每件都有序列号/批号),你想使用以太坊或 Wanchain 主网出售。 您将出售不可替代的代币,而买家将能够将这些代币交易给其他人。 每件艺术品一个令牌。 您向持有这些代币的任何人承诺,他们可以赎回他们的代币并实际拥有艺术品。

为此,只需将下面的代码粘贴到 Remix 中并部署智能合约。 您将为每件想看的新艺术品“铸造”一个代币。 然后,当您交出对该物品的实际占有时,您将“烧毁”该令牌。

pragma solidity ^0.8.0;

import "https://github.com/0xcert/ethereum-erc721/src/contracts/tokens/nf-token-metadata.sol";
import "https://github.com/0xcert/ethereum-erc721/src/contracts/ownership/ownable.sol";

/**
 * @dev This is an example contract implementation of NFToken with metadata extension.
 */
contract MyArtSale is
  NFTokenMetadata,
  Ownable
{

  /**
   * @dev Contract constructor. Sets metadata extension `name` and `symbol`.
   */
  constructor()
  {
    nftName = "Frank's Art Sale";
    nftSymbol = "FAS";
  }

  /**
   * @dev Mints a new NFT.
   * @param _to The address that will own the minted NFT.
   * @param _tokenId of the NFT to be minted by the msg.sender.
   * @param _uri String representing RFC 3986 URI.
   */
  function mint(
    address _to,
    uint256 _tokenId,
    string calldata _uri
  )
    external
    onlyOwner
  {
    super._mint(_to, _tokenId);
    super._setTokenUri(_tokenId, _uri);
  }

}

您应该在举行拍卖或出售任何东西之前联系律师。 具体而言,拍卖法因司法管辖区而异。 此应用程序仅作为技术示例提供,并非法律建议。

Validation

您可以使用在线验证器检查智能合约的有效性、实施的正确性以及相应智能合约的支持功能https://erc721validator.org/。

Playground

Ethereum - Ropsten testnet

我们已经将一些合约部署到 Ropsten 网络。 你现在就可以和他们一起玩了。 无需安装软件。 在这个测试版本的合约中,任何人都可以铸造销毁代币,所以不要将它用于任何重要的事情。

ContractToken addressTransaction hash
nf-token.sol0xd8bbf8ceb445de814fb47547436b3cfeecadd4ec0xaac94c9ce15f5e437bd452eb1847a1d03a923730824743e1f37b471db0f16f0c
nf-token-metadata.sol0x5c007a1d8051dfda60b3692008b9e10731b67fde0x1e702503aff40ea44aa4d77801464fd90a018b7b9bad670500a6e2b3cc281d3f
nf-token-enumerable.sol0x130dc43898eb2a52c9d11043a581ce4414487ed00x8df4c9b73d43c2b255a4038eec960ca12dae9ba62709894f0d85dc90d3938280

Wanchain - testnet

我们已经将一些合约部署到 testnet 网络。 你现在就可以和他们一起玩了。 无需安装软件。 在这个测试版本的合约中,任何人都可以铸造销毁代币,所以不要将它用于任何重要的事情。

ContractToken addressTransaction hash
nf-token.sol0x6D0eb4304026116b2A7bff3f46E9D2f320df47D90x9ba7a172a50fc70433e29cfdc4fba51c37d84c8a6766686a9cfb975125196c3d
nf-token-metadata.sol0xF0a3852BbFC67ba9936E661fE092C93804bf1c810x338ca779405d39c0e0f403b01679b22603c745828211b5b2ea319affbc3e181b
nf-token-enumerable.sol0x539d2CcBDc3Fc5D709b9d0f77CaE6a82e2fec1F30x755886c9a9a53189550be162410b2ae2de6fc62f6791bf38599a078daf265580

Contributing

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

Bug bounty

您是阅读智能合约文档并了解 ERC-721 令牌参考实现如何工作的人。 所以你有独特的技能,你的时间很宝贵。 我们将以错误报告的形式支付您对该项目的贡献。

如果你的项目依赖于 ERC-721,或者你想帮助提高这个项目的保证,那么你可以承诺提供赏金。 这意味着您将承诺向证明存在问题的研究人员付费。 如果有兴趣,请通过 bounty@0xcert.org 联系我们。 谢谢。

阅读完整的漏洞赏金计划

Licence

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


!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
THIS PACKAGE HAS MOVED TO @nibbstack/erc721.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!



ERC-721 Token — Reference Implementation

This is the complete reference implementation of the ERC-721 non-fungible token standard for the Ethereum and Wanchain blockchains. It is also compatible with other EVM compatible chains like Binance Smart Chain (BSC), Avalanche (AVAX) etc. This is an open-source project, complete with Hardhat testing.

The purpose of this implementation is to provide a good starting point for anyone who wants to use and develop non-fungible tokens on the Ethereum and Wanchain blockchains. Instead of re-implementing the ERC-721 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. Note that this implementation is more restrictive then the ERC-721 standard since it does not support payable function calls out of the box. You are however free to add this yourself.

If you are looking for a more feature-rich and advanced ERC721 implementation, then check out the 0xcert Framework.

Structure

All contracts and tests are in the src folder. There are multiple implementations and you can select between:

  • nf-token.sol: This is the base ERC-721 token implementation (with support for ERC-165).
  • nf-token-metadata.sol: This implements optional ERC-721 metadata features for the token contract. It implements a token name, a symbol and a distinct URI pointing to a publicly exposed ERC-721 JSON metadata file.
  • nf-token-enumerable.sol: This implements optional ERC-721 support for enumeration. It is useful if you want to know the total supply of tokens, to query a token by index, etc.

Other files in the tokens and utils directories named erc*.sol are interfaces and define the respective standards.

Mock contracts showing basic contract usage are available in the mocks folder.

There are also test mocks that can be seen here. These are specifically made to test different edge cases and behaviours and should NOT be used as a reference for implementation.

Requirements

  • NodeJS 12+ is supported
  • Windows, Linux or macOS

Installation

npm

This is the recommended installation method if you want to use this package in your JavaScript project.

This project is released as an npm module. You must install it using the npm command:

$ npm install @0xcert/ethereum-erc721@2.0.0

Source

This is the recommended installation method if you want to improve the 0xcert/ethereum-erc721 project.

Clone this repository and install the required npm dependencies:

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

Make sure that everything has been set up correctly:

$ npm run test

Usage

npm

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

const contract = require("@0xcert/ethereum-erc721/build/nf-token-enumerable.json");
console.log(contract);

Remix IDE (Ethereum only)

You can quickly deploy a contract with this library using Remix IDE. Here is one example.

You have created and have possession of unique glass-blown artwork (each having a serial/lot number) which you would like to sell using the Ethereum or Wanchain mainnet. You will sell non-fungible tokens and the buyers would be able to trade those to other people. One token per piece of artwork. You commit to anybody holding these tokens that they may redeem their token and take physical possession of the art.

To do this, simply paste the code below into Remix and deploy the smart contract. You will "mint" a token for each new piece of artwork you want to see. Then you will "burn" that token when you surrender physical possession of the piece.

pragma solidity ^0.8.0;

import "https://github.com/0xcert/ethereum-erc721/src/contracts/tokens/nf-token-metadata.sol";
import "https://github.com/0xcert/ethereum-erc721/src/contracts/ownership/ownable.sol";

/**
 * @dev This is an example contract implementation of NFToken with metadata extension.
 */
contract MyArtSale is
  NFTokenMetadata,
  Ownable
{

  /**
   * @dev Contract constructor. Sets metadata extension `name` and `symbol`.
   */
  constructor()
  {
    nftName = "Frank's Art Sale";
    nftSymbol = "FAS";
  }

  /**
   * @dev Mints a new NFT.
   * @param _to The address that will own the minted NFT.
   * @param _tokenId of the NFT to be minted by the msg.sender.
   * @param _uri String representing RFC 3986 URI.
   */
  function mint(
    address _to,
    uint256 _tokenId,
    string calldata _uri
  )
    external
    onlyOwner
  {
    super._mint(_to, _tokenId);
    super._setTokenUri(_tokenId, _uri);
  }

}

You should contact a lawyer before holding an auction, or selling anything. Specifically, laws for auctions vary wildly by jurisdiction. This application is provided only as an example of the technology and is not legal advice.

Validation

You can check the validity of the smart contract, the correctness of the implementation and the supported functions of the respective smart contract using the online validator at https://erc721validator.org/.

Playground

Ethereum - Ropsten testnet

We already deployed some contracts to the Ropsten network. You can play with them RIGHT NOW. No need to install the software. In this test version of the contract, anybody can mint or burn tokens, so don't use it for anything important.

ContractToken addressTransaction hash
nf-token.sol0xd8bbf8ceb445de814fb47547436b3cfeecadd4ec0xaac94c9ce15f5e437bd452eb1847a1d03a923730824743e1f37b471db0f16f0c
nf-token-metadata.sol0x5c007a1d8051dfda60b3692008b9e10731b67fde0x1e702503aff40ea44aa4d77801464fd90a018b7b9bad670500a6e2b3cc281d3f
nf-token-enumerable.sol0x130dc43898eb2a52c9d11043a581ce4414487ed00x8df4c9b73d43c2b255a4038eec960ca12dae9ba62709894f0d85dc90d3938280

Wanchain - testnet

We already deployed some contracts to testnet network. You can play with them RIGHT NOW. No need to install software. In this test version of the contract, anybody can mint or burn tokens, so don't use it for anything important.

ContractToken addressTransaction hash
nf-token.sol0x6D0eb4304026116b2A7bff3f46E9D2f320df47D90x9ba7a172a50fc70433e29cfdc4fba51c37d84c8a6766686a9cfb975125196c3d
nf-token-metadata.sol0xF0a3852BbFC67ba9936E661fE092C93804bf1c810x338ca779405d39c0e0f403b01679b22603c745828211b5b2ea319affbc3e181b
nf-token-enumerable.sol0x539d2CcBDc3Fc5D709b9d0f77CaE6a82e2fec1F30x755886c9a9a53189550be162410b2ae2de6fc62f6791bf38599a078daf265580

Contributing

See CONTRIBUTING.md for how to help out.

Bug bounty

You are somebody that reads the documentation of smart contracts and understands how the ERC-721 Token Reference Implementation works. So you have unique skills and your time is valuable. We will pay you for your contributions to this project in the form of bug reports.

If your project depends on ERC-721 or you want to help improve the assurance of this project then you can pledge a bounty. This means you will commit to paying researchers that demonstrate a problem. Contact us at bounty@0xcert.org if interested. Thank you.

Read the full bug bounty program.

Licence

See LICENSE for details.

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