본문 바로가기

TIL

TIL) ERC721 활용하여 테스트넷에 NFT 발행하고 OpenSea에서 확인하기

#활용한 tool

Remix

AWS S3 버킷

openzeppelin

 

#작업순서

  • Remix에서 openzeppelin library importing
  • contract 작성
  • compile 및 deploy
  • 이미지 및 속성값 담은 properties.json 작성
  • AWS S3 버킷에 properties.json 업로드
  • json 파일의 url 바탕으로 minting
  • openSea testnet에서 확인

 

#전체코드

contract part

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.7;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";

contract MyNFTs is ERC721URIStorage, Ownable{
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;

    constructor() ERC721("MyNFT", "NFT") {}

    function mintNFT(address recipient, string memory tokenURI) public onlyOwner returns (uint256) {
        _tokenIds.increment();

        uint256 newItemId = _tokenIds.current();
        _mint(recipient, newItemId);
        _setTokenURI(newItemId, tokenURI);

        return newItemId;
    }
}

properties part

{
    "name": "holyShit #1",
    "description": "holy creature's shit is also holt",
    "image": "https://pbs.twimg.com/profile_images/704509757877391360/PhH9dkJy_400x400.jpg",
    "attributes": [
        {
            "trait_type": "Power",
            "value": "Max"
        }
    ]
}

 

 

#trouble shotting

  • AWS S3에 올린 json 파일에 접근하기 위해서는 읽기 권한을 퍼블릭으로 바꿔줘야 함
  • opensea testnet은 Rinkeby 네트워크만 지원

 

 

#추가로 구현할 기능

  • 민팅가격설정