OpenZeppelin의 ERC-721보기 : Minter의 목적 (MinterRole)

This article is meant to explain how Minters or people who are allowed to mint are determined in the ERC-721 토큰 표준 . This article aims to help beginners like me, who are still starting out in learning about Blockchain technology.

자기소개



안녕하세요, 샘 ( @sbenemerito )입니다. 오쿠타마의 유학생입니다. 일본어와 블록체인 기술을 공부하고 있습니다. 2018년 10월에 일본에 필리핀에서 왔습니다.

개요



We will be learning about the ERC-721 Non-Fungible Token Standard through OpenZeppelin's ERC-721 토큰 구현 . This article will focus on the discussion of the role of Minters in the ERC-721 ecosystem.

ERC-721이란?



ERC-721은 토큰 기준. 다양한 자산을 관리할 수 있습니다. 예를 들어, CryptoKitties는 ERC-721 토큰 기준으로 자산을 관리합니다.

기사
htps : // 기주 b. 이 m / 에어 ㄴ m / 에이 Ps / b ぉ b /까지 r / 에이 PS / 에이 p-721. md

OpenZeppelin이란?



OpenZeppelin is an open-source library for smart contracts, especially used for token implementation.

공식 사이트
ぺぺぺㅜㅜㅜㅜㅜㅜㅜㅜㅜㅜㅜㅜㅜㅜㅜㅜㅜㅜㅜㅜ rg/

코드
htps : // 기주 b. 코 m / 오펜 젠 / 오 펜 펜 - 소 티

Minting



민트하는 것은 ERC-721 토큰 기준에 토큰을 만드는 방법입니다. "Token minters"는 박하를하고 있습니다.

However, not everyone in the network can mint tokens. So, how do we determine who can mint? We assign the role of 'minter' to certain users.

OpenZeppelin's MinterRole Implementation



We will be taking a look at how OpenZeppelin implements the restriction of MinterRole.

문헌집
ぺぺぺㅜㅜㅜㅜㅜㅜㅜㅜㅜㅜㅜㅜㅜㅜㅜㅜㅜㅜㅜㅜㅜㅜ 오 rg/아피/도 cs/아세트 s_로ぇs_민테로로. HTML

코드
htps : // 기주 b. 코 m/오펜젠페엔/오펜젠페소-소 ty/bぉb/어서 r/안 t라 cts/아세스 s/로ぇs/민테로로. 그 l

Solidity의 버전 및 Role import



MinterRole.sol
pragma solidity ^0.4.24;

import "../Roles.sol";

contract MinterRole {
  ...
}

On the first line, the version of Solidity used in the smart contract is being defined. Then, the Role library is being imported. Next, is where the smart contract for MinterRole lies.

Constructor 함수



MinterRole.sol
contract MinterRole {
  using Roles for Roles.Role;

  event MinterAdded(address indexed account);
  event MinterRemoved(address indexed account);

  Roles.Role private minters;

  constructor() public {
    _addMinter(msg.sender);
  }
}

From here on, we will be using the previously imported Role library for all Roles.Role types. We then have two events being defined, "MinterAdded"and "MinterRemoved", which basically keeps track of all user addresses being added or removed as The "minters"variable is then defined to keep track of all minters. Finally, the contract creator is set as a minter by default on the constructor function.

Inspecting MinterRole.sol



MinterRole.sol
contract MinterRole {
  ...
  modifier onlyMinter() {
    require(isMinter(msg.sender));
    _;
  }

  function isMinter(address account) public view returns (bool) {
    return minters.has(account);
  }
  ...
}

Here, we create a modifier onlyMinter(), which extends the isMinter() function. Basically, these parts of the code will be called to check if a user (by his/her address) is a Minter.

기본 함수



MinterRole.sol
contract MinterRole {
  ...
  function addMinter(address account) public onlyMinter {
    _addMinter(account);
  }

  function renounceMinter() public {
    _removeMinter(msg.sender);
  }

  function _addMinter(address account) internal {
    minters.add(account);
    emit MinterAdded(account);
  }

  function _removeMinter(address account) internal {
    minters.remove(account);
    emit MinterRemoved(account);
  }
  ...
}

These are the core functions of the MinterRole smart contract. The function addMinter() enables us to assign the Minter role to a certain user. Then, renounceMinter() is a function that can be called by a user to surrender his Minter role. Finally , removeMinter() is a function used to remove a certain user from the list of Minters.

결론



In the ERC-721 Non-Fungible Token Standard, there is a limited number of users who are allowed to mint or create new tokens. By creating a Minter role, like what was discussed (OpenZeppelin's implementation), we are able to e the minters are in the network.

I hope you learned something, if not a lot, in this article I recommend that you check out these links:
  • ERC-721 Non-Fungible Token Standard
  • OpenZeppelin Documentation
  • OpenZeppelin GitHub 리포지토리
  • 좋은 웹페이지 즐겨찾기