pragma solidity ^0.8.24;
contract MyNFT is ERC721{
using Strings for uint256;
address owner;
uint256 public maxSupply = 10;
bool private isOpened = false;
uint256 public counter = 0;
modifier onlyOwner {
require(msg.sender == owner);
_;
}
constructor (string memory _name, string memory _symbol) ERC721(_name, _symbol){
owner = msg.sender;
}
function openBlindBox() external onlyOwner {
isOpened = true;
}
function _baseURI() internal pure overrider returns (string memory) {
return ipfs://QmahbazMeYgjSyKuSLZ6EqGWVKYYKEtDnH1gXdGGioiYnX";
}
function tokenURI(uint256 tokenId) public view override returns (string memory) {
if(!isOpenid) {
return _baseURI();
}
return string(abi.encodePacked("ipfs://QmahbazMeYgjSyKuSLZ6EqGWVKYYKEtDnH1gXdGGioiYnX");
}
function mint (uint256 amount) external {
require(amount + count <= maxSupply, "over max supply.");
for(uint256 i = 0; i < amount ; i++){
_mint(msg.sender, counter);
counter ++;
}
}
}
pragma solidity ^0.8.24;
contract MyNFT is ERC721{
using Strings for uint256;
address owner;
uint256 public maxSupply = 10;
bool private isOpened = false;
uint256 public counter = 0;
modifier onlyOwner {
require(msg.sender == owner);
_;
}
constructor (string memory _name, string memory _symbol) ERC721(_name, _symbol){
owner = msg.sender;
}
function openBlindBox() external onlyOwner {
isOpened = true;
}
function _baseURI() internal pure overrider returns (string memory) {
return ipfs://QmahbazMeYgjSyKuSLZ6EqGWVKYYKEtDnH1gXdGGioiYnX";
}
function tokenURI(uint256 tokenId) public view override returns (string memory) {
if(!isOpenid) {
return _baseURI();
}
return string(abi.encodePacked("ipfs://QmahbazMeYgjSyKuSLZ6EqGWVKYYKEtDnH1gXdGGioiYnX");
}
function mint (uint256 amount) external {
require(amount + count <= maxSupply, "over max supply.");
for(uint256 i = 0; i < amount ; i++){
_mint(msg.sender, counter);
counter ++;
}
}
}
Solidity 實戰系列工作坊第 3 場精彩重播: ERC20 同質化代幣與 ERC721 NFT 非同質化代幣