当前位置:网站首页>NFT smart contract release, blind box, public offering technology practice -- contract
NFT smart contract release, blind box, public offering technology practice -- contract
2022-07-06 07:57:00 【NFT practitioner】
This article mainly introduces you from the perspective of Technology nft Mainstream gameplay - issue , Blind box , Public offering and other process steps , This is also the way most projects in the market play .
This article nft Development is mainly divided into two parts : 1. The contract part 2. Jigsaw puzzle part .
This time Nft I'm also going to explain the Development Series in two articles , Today we will mainly talk about the contract .
The contract part mainly includes the following functions :
Establish and eth Test the smart contract of network interaction
Nft To be able to be mint
Nft Be able to set the total amount
Nft Set the maximum holding of each address
Nft Be able to limit single mint The amount of
Nft Be able to set the switch to go public
The puzzle part mainly includes the following functions :
How to quickly make a variety of puzzles and meta Information
How to upload ipfs Interstellar network system ( Test net )
These are the technical points that need to be explained in this article .
Before development , You need to prepare the following tools and environments .
metamask Wallet plug-in
remix Online compilation environment
Specific wallet installation and remix Use , No more explanation here .
The contract part
First, paste the source code of this contract directly in remix To compile . Source code is as follows :
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
contract NftMeta is ERC721Enumerable, Ownable {
using Strings for uint256;
// Whether to permit nft Sell - switch
bool public _isSaleActive = false;
// Initialize the blind box , Wait until a certain time to open the box randomly , become true
bool public _revealed = false;
// nft Total quantity
uint256 public constant MAX_SUPPLY = 10;
// Casting Nft The price of
uint256 public mintPrice = 0.3 ether;
// There can only be one purse cast nft Number
uint256 public maxBalance = 1;
// once mint Of nft The number of
uint256 public maxMint = 1;
// After the blind box switch is turned on , Need to display the picture of unpacking base Address
string baseURI;
// Blind box pictures meta,json Address , It will be mentioned later
string public notRevealedUri;
// Extension type of default address
string public baseExtension = ".json";
mapping(uint256 => string) private _tokenURIs;
// Constructors
constructor(string memory initBaseURI, string memory initNotRevealedUri)
ERC721("Nft Meta", "NM") // Realized ERC721 The parent constructor of , Is an implementation of subclass inheritance
{
setBaseURI(initBaseURI);
setNotRevealedURI(initNotRevealedUri);
}
// Cast at an external address nft Function call for
function mintNftMeta(uint256 tokenQuantity) public payable {
// Verify the total supply + Quantity per casting <= nft Total quantity
require(
totalSupply() + tokenQuantity <= MAX_SUPPLY,
"Sale would exceed max supply"
);
// Verify whether the opening status is enabled
require(_isSaleActive, "Sale must be active to mint NicMetas");
// Verify... In the address of the cast wallet nft The number of + The quantity of this casting <= The biggest possession of this wallet nft The number of
require(
balanceOf(msg.sender) + tokenQuantity <= maxBalance,
"Sale would exceed max balance"
);
// Check the quantity of this casting * The price of casting <= Attached to this message eth The number of
require(
tokenQuantity * mintPrice <= msg.value,
"Not enough ether sent"
);
// Check the quantity of this casting <= The maximum quantity cast this time
require(tokenQuantity <= maxMint, "Can only mint 1 tokens at a time");
// The above verification conditions are met , Conduct nft The casting of
_mintNftMeta(tokenQuantity);
}
// Casting
function _mintNftMeta(uint256 tokenQuantity) internal {
for (uint256 i = 0; i < tokenQuantity; i++) {
// mintIndex It's casting nft The serial number of , According to the total supply from 0 Start accumulating
uint256 mintIndex = totalSupply();
if (totalSupply() < MAX_SUPPLY) {
// call erc721 Safe casting method of
_safeMint(msg.sender, mintIndex);
}
}
}
// Return each nft Address of the Uri, It contains nft The whole message , Including the name , describe , Properties, etc
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
// The blind box has not been opened , Then the default is a black background picture or other pictures
if (_revealed == false) {
return notRevealedUri;
}
string memory _tokenURI = _tokenURIs[tokenId];
string memory base = _baseURI();
// If there is no base URI, return the token URI.
if (bytes(base).length == 0) {
return _tokenURI;
}
// If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked).
if (bytes(_tokenURI).length > 0) {
return string(abi.encodePacked(base, _tokenURI));
}
// If there is a baseURI but no tokenURI, concatenate the tokenID to the baseURI.
return
string(abi.encodePacked(base, tokenId.toString(), baseExtension));
}
// internal
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
//only owner
function flipSaleActive() public onlyOwner {
_isSaleActive = !_isSaleActive;
}
function flipReveal() public onlyOwner {
_revealed = !_revealed;
}
function setMintPrice(uint256 _mintPrice) public onlyOwner {
mintPrice = _mintPrice;
}
function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
notRevealedUri = _notRevealedURI;
}
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
function setBaseExtension(string memory _newBaseExtension)
public
onlyOwner
{
baseExtension = _newBaseExtension;
}
function setMaxBalance(uint256 _maxBalance) public onlyOwner {
maxBalance = _maxBalance;
}
function setMaxMint(uint256 _maxMint) public onlyOwner {
maxMint = _maxMint;
}
function withdraw(address to) public onlyOwner {
uint256 balance = address(this).balance;
payable(to).transfer(balance);
}
}
The above is the contract source code .

Yes erc721 The extension part and permission part of , Inherit at the same time , rewrite erc721 Part of the way , As we'll see .

These state variables are mainly used for Nft Set some properties of , Including the total amount , Each address has a maximum of mint The quantity of .

The above is the realization of the casting method , Check the conditions before casting , And then call erc721 Of _safemint Cast in a safe way .
Deploy the contract code , There are several points to note

At the same time, switch the test network to Rinkeby Test net , At the same time, it needs to be passed in advance faucet Receive the test currency . Receiving address :
Faucets | ChainlinkGet testnet LINK for an account on one of the supported blockchain testnets so you can create and test your own oracle and Chainlinked smart contract.
https://faucets.chain.link/FaucETH
https://fauceth.komputing.org/
Rinkeby: Authenticated Faucet
https://faucet.rinkeby.io/ After deployment , There will be

In us mint Before , It is necessary to turn on the casting switch ( In the red frame ), Click to change the status variable to true.
The red function is the casting method , Fill in quantity 1, At the same time, because we set the minimum in the state variable of the contract Mint The price of is 0.3ether, So we need to be in msg.value With ether Quantity to complete mint.

Because it is not allowed to enter decimals in the red box , therefore , adopt ether The website performs fee unit conversion
Ethereum Unit Converter | Ether to Gwei, Wei, Finney, Szabo, Shannon etc.
https://eth-converter.com/

take 0.3ether Input , To get Gwei The number of , Assign this quantity to the red box above mint. After success , Will be in ipfs The test network sees a card numbered 0 Pictures of the .ipfs Test network address :

thus , We nft The contract part under development has been completed .
边栏推荐
- 软件开发的一点随记
- TS类型体操 之 字符串的妙用
- Type of data in energy dashboard
- Asia Pacific Financial Media | "APEC industry +" Western Silicon Valley invests 2trillion yuan in Chengdu Chongqing economic circle to catch up with Shanghai | stable strategy industry fund observatio
- Generator Foundation
- [Yugong series] February 2022 U3D full stack class 011 unity section 1 mind map
- ROS learning (IX): referencing custom message types in header files
- National economic information center "APEC industry +": economic data released at the night of the Spring Festival | observation of stable strategy industry fund
- Artcube information of "designer universe": Guangzhou implements the community designer system to achieve "great improvement" of urban quality | national economic and Information Center
- flask返回文件下载
猜你喜欢

Secure captcha (unsafe verification code) of DVWA range

Parameter self-tuning of relay feedback PID controller

珠海金山面试复盘

Significance and measures of encryption protection for intelligent terminal equipment

【Redis】NoSQL数据库和redis简介

【T31ZL智能视频应用处理器资料】

Google may return to the Chinese market after the Spring Festival.
![[非线性控制理论]9_非线性控制理论串讲](/img/a8/03ed363659a0a067c2f1934457c106.png)
[非线性控制理论]9_非线性控制理论串讲

解决方案:智慧工地智能巡检方案视频监控系统

Uibehavior, a comprehensive exploration of ugui source code
随机推荐
edge浏览器 路径获得
How to prevent Association in cross-border e-commerce multi account operations?
Helm install Minio
Oracle time display adjustment
【T31ZL智能视频应用处理器资料】
08- [istio] istio gateway, virtual service and the relationship between them
649. Dota2 Senate
Interview Reply of Zhuhai Jinshan
A Closer Look at How Fine-tuning Changes BERT
Mex related learning
flask返回文件下载
[Yugong series] creation of 009 unity object of U3D full stack class in February 2022
National economic information center "APEC industry +": economic data released at the night of the Spring Festival | observation of stable strategy industry fund
Common functions for PHP to process strings
22. Empty the table
Circuit breaker: use of hystrix
C # create database connection object SQLite database
Data governance: data quality
C # connect to SQLite database to read content
Generator Foundation