1) 데이터 관리 방법 - 폴더째로 IPFS에 이미지와 JSON파일을 넣기
2) 민트 방법 - 한번에 많이 민팅할 수 있는 코드를 사용
과정
1) 이미지를 준비한다.
2) 이미지를 폴더째로 ipfs에 올린다. (이후 수정이 불가능)
"나중에, json 파일을 업로드 할때, 폴더 경로는 모든 nft가 똑같게 해놓고, 뒤에 바뀌는 것만 바꾸면 된다.
/2.json, /3.json 같이..."
3) JSON 파일을 업데이트한다. (이미지를 ipfs에 올리고, cid를 json 파일에 넣어야 함)
{
"attributes" : [ {
"trait_type" : "Breed",
"value" : "Maltipoo"
}, {
"trait_type" : "Eye color",
"value" : "Mocha"
} ],
"description" : "The world's most adorable and sensitive pup.",
"image" : "ipfs://Qmf7ZHtxQL1Vk3dC6k4vnsmBcy9wkv52NbiXFMe9ZyuVWt/5.png",
//이미지 안에, ipfs:// cid값 넣기 // 1.png, 2.png, 3.png, 4.png, 5.png 구분하기"name" : "DangDangYi5"
}
사실 Node.js로 자동으로 만들 수 있음!
4) JSON 파일을 폴더째로 ipfs에 올린다.(이후 수정 불가)
5) 민팅
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
contract MyToken is ERC721, Ownable {
using Counters for Counters.Counter;
string public fileExtention = ".json";
using Strings for uint256;
Counters.Counter private _tokenIdCounter;
constructor() ERC721("MyToken", "MTK") {}
function _baseURI() internal pure override returns (string memory) {
return "ipfs://QmZK2MJCvBRWdGxJ5pNe2uz67QfLFggi2fDx51yvPfA84H/";
//Pinata에 CID를 넣기
}
function safeMint(address to) public onlyOwner {
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(to, tokenId);
}
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString(), fileExtention)) : "";
}
function batchMint(address to, uint amount) public onlyOwner{
for (uint i = 0; i < amount; i++) {
safeMint(to);
}
}
}

1)우선 확인용이므로, safe mint에 '메타마스크 연결'하지 말고, 그냥 Remix VM으로 연결해서 확인해 보고,
사진을 총 5개 올렸으므로, 5번 클릭하기
2) tokenURI에 숫자를 누르면, 1,2,3,4,5를 눌러보면 /1.json, /2.json 바뀌는 것이 확인이 된다.
대량으로 처리가 가능하다.
Share article