本文介绍一种通过自己部署智能合约,在 OpenSea 上创建自己的 NFT 商店的方法;
1.ERC721合约
写一个最简单的标准 ERC721 合约,源码:
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../openzeppelin/contracts/token/ERC721/ERC721.sol";
/*
* @title standard ERC721 NFT
*/
contract StandNFT is ERC721 {
uint256 public mintNum;
uint256 public totalSupply;
mapping(uint256 => string) private _tokenURI;
constructor(
string memory name_,
string memory symbol_,
uint256 totalSupply_
)
ERC721(name_, symbol_)
{
totalSupply = totalSupply_;
}
function mint(address to_) public returns (bool) {
mintNum ++ ;
require(totalSupply >= mintNum , "mint number is insufficient");
_mint(to_, mintNum);
return true;
}
function setURI(uint256 _id, string memory _uri) public {
_tokenURI[_id] = _uri;