提案種類
提案流程
https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1.md
https://docs.openzeppelin.com/contracts/5.x/
以太坊上的「同質化代幣」標準。
https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol
狀態變數:
Function:
Demo
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.20;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract ERC20Example is ERC20 {
// 定義最大供給量
uint256 public maxSupply;
//建構子初始化ERC20必要參數(name與symbol),並多加設定題目要求的maxSupply
constructor(
string memory _name,
string memory _symbol,
uint256 _maxSupply
) ERC20(_name, _symbol){
//執行時填入10000000000(100億) * 1000000000000000000(單位)
maxSupply = _maxSupply;
}
// 實作mint function,主要用來demo確認用
function mint (uint256 amount) external {
//判斷這筆交易若完成,是否會超出最大供給量,如果會就回傳錯誤字串"over max supply."
require(amount + totalSupply() <= maxSupply, "over max supply.");
_mint(msg.sender, amount);
}
}
以太坊上的「非同質化代幣」標準。
https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/ERC721.sol
狀態變數:
Funtion:
Demo
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
contract ERC721Example is ERC721 {
// 定義最大供給量
uint256 public maxSupply;
uint256 public counter = 0;
modifier avaialbeMint(uint256 amount) {
//判斷這筆交易若完成,是否會超出最大供給量,如果會就回傳錯誤字串"over max supply."
require(amount + counter <= maxSupply, "over max supply.");
_;
}
//建構子初始化ERC721必要參數(name與symbol),並多加設定題目要求的maxSupply
constructor(
string memory _name,
string memory _symbol,
uint256 _maxSupply)
ERC721(_name, _symbol){
//執行時填入10
maxSupply = _maxSupply;
}
// 實作mint function,主要用來demo確認用
function mint (uint256 amount) external avaialbeMint(amount){
// 迴圈值星批量鑄造NFT
for(uint256 i=0; i < amount ; i++){
// 鑄造 NFT, counter為NFT的tokenId
_mint(msg.sender, counter);
counter ++ ;
}
}
// 讓transfer無效
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public override {
revert();
}
}
https://docs.opensea.io/docs/metadata-standards
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.20;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
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;
}
//設定NFT的baseURI(盲盒)
function _baseURI() internal pure override returns (string memory) {
return "ipfs://QmXxZBg4RnGxC2dDxfUSAmxgGooHsoncPQgCLiNw8kj3Ls/";
}
//查看NFT Metadata網址
function tokenURI(uint256 tokenId) public view override returns (string memory) {
if (!isOpened){
return _baseURI();
}
return string(abi.encodePacked("ipfs://QmWQcaFFCm9ofyVN2ZwGbTGopLEbQ6QSc2Xn1C7ekKAYDF/", tokenId.toString(), ".json"));
}
// 實作mint function,主要用來demo確認用
function mint (uint256 amount) external{
require(amount + counter <= maxSupply, "over max supply.");
// 迴圈批量鑄造NFT
for(uint256 i=0; i < amount ; i++){
// 鑄造 NFT, counter為NFT的tokenId
_mint(msg.sender, counter);
counter ++ ;
}
}
}