카테고리 없음

[ethereum] ERC721을 이용한 NFT 만들기 - 3편

멍개. 2022. 8. 28. 07:02
NFT 생성기 NFT 등록 로딩중 모바일

 

 

 

▶ ropsten 네트워크 배포

https://ropsten.etherscan.io/token/0x4fAb976447Abfab5ba35C94e298865409a9ddc6c

 

() Token Tracker | Etherscan

() Token Tracker on Etherscan shows the price of the Token $0.00, total supply 0, number of holders 1 and updated information of the token. The token tracker page also shows the analytics and historical data.

ropsten.etherscan.io

 

▶ ropsten 네트워크 배포 - NFT 생성기

https://inspiring-newton-bf922b.netlify.app

 

NFT Generator

 

inspiring-newton-bf922b.netlify.app

 

▶ solidity 0.5에서 0.8.9로 컨버팅

ERC721의 인터페이스가 아닌 mint 함수를 추상 컨트랙트를 통해 인터페이스를 제공하여 명확한 형태의 코드로 개선하였습니다.

https://github.com/Exchange-M/NFT-ERC721

 

GitHub - Exchange-M/NFT-ERC721: ERC721 for NFT

ERC721 for NFT. Contribute to Exchange-M/NFT-ERC721 development by creating an account on GitHub.

github.com

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

import 'https://github.com/Exchange-M/NFT-ERC721/blob/master/ERC721.sol';

contract Minty_ERC721 is Minty, ERC721 {
    // Counters.Counter 타입인 _ownedTokensCount[uint]가 library Counters에 정의된 increment(), decrement(), current()를 호출하기 위해 필요
    using Counters for Counters.Counter;
    
    function _mint(address to, uint256 tokenId) internal override {
        require(to != address(0), "ERC721: mint to the zero address");
        require(!_exists(tokenId), "ERC721: token already minted");

        _tokenOwner[tokenId] = to;
        _ownedTokensCount[to].increment();

        emit Transfer(address(0), to, tokenId);
    }
}

contract CharactorByERC721 is Minty_ERC721 {
    struct Charactor {
        string  name;  // 캐릭터 이름
        uint256 level; // 캐릭터 레벨
    }

    Charactor[] public charactors; // default: [] 
    address public owner;          // 컨트랙트 소유자

    constructor () {
        owner = msg.sender; 
    }

    modifier isOwner() {
      require(owner == msg.sender);
      _;
    }

    // 캐릭터 생성
    function mint(string memory name, address account) public isOwner {
        uint256 cardId = charactors.length; // 유일한 캐릭터 ID
        charactors.push(Charactor(name, 1));
        _mint(account, cardId); // ERC721 소유권 등록
    }
}