Original title: "A detailed analysis of the NFT purchase process and how scientists snapped up NFT"
Original author: iamcatcher
This article is based on my recent study and discussion with group friends. As a record, I finally think about the status quo of the NFT industry. When I first came into contact with blockchain and Ethereum programming, it is inevitable that there will be mistakes. Everyone is welcome to correct and communicate.

Simply speaking, the purchase process is your wallet Interact with the NFT contract, transfer 0.176ETH from your wallet to the contract, call the contract mint method, generate two NFT tokens, transfer the tokens to your wallet, and you get this NFT.
For the content of NFT contracts, please refer to the following article: Technology sharing behind NFT and OpenSea transactions— Mirror
Click the mint button on the official website of the project party, and open the end-to-end interaction process from the browser to the Ethernet network in detail:
< p>
1. Click the Mint button
Everyone log in to the project website, connect your wallet on Chrome, and click the mint button. The JavaScript code on the web page generates raw transaction data based on the mint price of the project, the contract address, etc., mainly including the following key fields


2、TX Signature
When the web page code interacts with Metamask, a window will pop up for you Confirm this transaction. After clicking Confirm, Metamask will use your wallet private key to sign to ensure that the transaction is authorized by you, and the subsequent Ethereum network will verify it.
3. Send TX to node for verification
p>
The transaction TX is sent by Metamask to Metamask’s Ethereum node (default configuration), and the node verifies the TX verification to ensure that transactions are not counterfeited.
4. Broadcast TX to the Ethereum network
< /p>
The transaction TX is sent to the adjacent nodes of the Ethereum network, and then broadcast to the adjacent nodes contact. At this time, your transaction can be viewed on etherscan.io, and the status is pending.
5. Miner node receives TX
p>
The miner node will put the synchronized tx in a place called Txpool/Mempool, which is The key to many things needs to be expanded:

Txpool code flow (borrowed from the txpool diagram of Ethereum source code analysis)
< /p>
The data source of Txpool mainly comes from:
Local submission, that is, the transaction submitted by the third-party application by calling the RPC service of the local Ethereum node;
Remote synchronization, It refers to synchronizing the transaction data of other Ethereum nodes to the local node through the form of broadcast synchronization;
The main rules are as follows:
1) Prioritize Gasprice High TX
2) Local TX is prioritized over remote synchronization
3) Each node will set a minimum Gasprice, and remote TX below this value will be discarded
The TX in Pending is obtained and verified by the Miner module and used for mining; after successful mining, write Into the block and broadcast. The miner takes away the transaction is a copy, and the TX in the Txpool does not decrease. TX is deleted from Txpool after it is written into the chain.
The TX whose Gas is too low will always be stuck in the Txpool and cannot be processed. It is necessary to increase the Gas to allow it to be processed.
For detailed code analysis, please refer to the txpool of Ethereum source code analysis
GasWar: When a popular transaction occurs, everyone can be prioritized for their own TX and compete to increase the Gas fee< /p>
6. The miner's block TX is packaged
p>
The miner selects TX and starts mining, then finds a block solution and broadcasts it to the Ethereum network .
7. The block is verified
After verification by other miner nodes, the block is officially uploaded to the chain, and our TX results can be found in etherscan Viewed on .io.
8. TX status synchronization
The relevant status is returned locally and can be queried on Metamask.
Reference document:
p>
Life Cycle of an Ethereum Transaction
Transaction lifecycle on the Ethereum blockchain
The Influence Factors on Ethereum Transaction Fees
p>
How the contract is executed
Simply speaking, the transaction we send will be Convert it into a Message object and pass it into the EVM, and the EVM will generate a Contract object based on the Message for subsequent execution. The mint function is called on the input of the contract based on the Data we transferred.
See the EVM introduction for details and refer to the following document:
< /p>
easy-evm
learnblockchain.cn
NFT pre-sale and public sale
Pre-sale can only be purchased for specific users, public sale is for everyone All can be snapped up.
There are two main technical questions to be answered here:
1. How to limit specific wallets to mint?
2. How does the state switch between pre-sale and public sale?
Whitelists are now commonly implemented using Merkle trees. Simply put, all whitelist wallet addresses are used as leaf nodes of the Merkle tree to generate a Root hash. In the contract, only the Root hash value needs to be stored. When the mint function is called, the JS code of the webpage generates a proof based on the wallet address (the hash of the parent node of the address), and the contract can verify whether the address belongs to the whitelist.
Take the C01 contract as an example:
0x6fd053bff10512d743fa36c859e49351a4920df6

Update the hash through SetRoot during the pre-sale and public sale (C01 uses a whitelist for both sales, and the public sale uses a capital verification lottery)

For detailed principles and codes, refer to the following article: Using Merkle Trees for NFT Whitelists
Sale Status Switch
p>
Two methods are commonly used:
1) By judging the time point in the contract, such as 2022-01-01 18:00 UTC to start public sales p>
2) Judging by the state, and setting the state variables in the contract, such as taking the XRC contract as an example, to judge the Status.PublicSale state, which is set by calling SetStatus in the contract.

Scientists use programs to snap up NFT, that is Use various means to make your own transaction TX can be packaged by miners before others, and complete NFT mint before it is sold out. At the same time, scientists are all pursuing perfection. The most perfect result is of course that their TX appears in the first block that meets the public sale status, which is to grab Block0.
The Block0 of the two scenarios is as shown in the figure below. At the same time, Block0 can also avoid subsequent panic buying Gaswar, reducing snapping costs. But now it is getting more and more complicated, and Gaswar will also occur in Block0. For example, the public sale of XRC is less than 200, and the number of TX of scientists entering Block0 is >200.

Block0 in two scenarios< /blockquote>
The methods used by scientists can be summed up in the following three points:
1. Lower information acquisition delay
< /p>
Similar to financial quantitative transactions, funds expect lower latency between their servers and exchanges. The blockchain is similar. For example, everyone in CEX will connect to the server of the centralized exchange nearby. The transactions of NFT mint and DeFi happen in the Ethereum network. Everyone is pursuing a faster Ethereum Node or a network connected to a large mining pool, so as to monitor the pending TX of Txpool faster, obtain the required information, and execute the program in a timely manner.
2. The transaction path is shorter
< /p>
1), directly looking at the above TX interaction process, the choice of scientists must be directly through the program and NFT contracts to interact.
2) By deploying your own contracts on the chain, you can interact with NFT contracts through private contracts. Although private contracts require external TX triggers, contracts can be purchased in batches, which is especially suitable for NFTs that do not limit the number of mints. (Now more and more NFTs restrict the caller to be a contract)
3. Submit transactions in batches
In addition to the private contract mint mentioned above In addition, if the project limits the number of mints for each address, multiple TXs can be packaged and submitted together through Flashbots.
Contract mint
An example of contract snap-up, after YOKAI’s public sale. Scientists snapped up a total of 750 mints using private contracts. See TX for details.
YOKAI contract code, there is no limit to how many mints an address can have, only 2 mints per tx. So it was booked by scientists.
Flashbots
< p>For detailed explanation of Flashbots, please refer to Mr. There are no ETH wallets to withdraw assets or interactive contracts—Mirror
There are several advantages of using Flashbots:
1) You can package TX in batches and submit together, and you can independently control the order of packaging TX.
2) The TX submitted by Flashbots will not appear in Txpool, it will be seen by everyone after appearing on the chain. This provides the privacy of TX, so many DeFi quantitative trading platforms advertise their access to Flashbots. (I personally think this is only temporary. With the widespread use of Flashbots, the TX submitted by Flashbots will still be monitored)
3) If you fail to pass the Flashbots mint, you will not be charged gas fees
Flashbots snap up Let’s take Lengtu’s XRC public sale as an example:
Boss Yi tweeted that the public sale will not be public sale by scientists, but the result is that the battle is resolved at block=14020984 Block0, and all scientists are reserved.
The setStatus TX sent by the project party was monitored in TXpool at 14020982
< p>
< p> Then some scientists packaged setStatus TX and their own mint tx with flashbots and sent them to miners. Here the scientist puts setStatus TX first, although it has a low Gas, it ranks its own mint tx behind, and finally tx enters the chain at block 984.
Flashbots Packaging Query Link
< p>
Burning blocks
p>
To put it simply, it is to send tx non-stop. If you send more mint, the probability of success will be higher. If you are lucky, you may be squeezed into Block0. The problem with this solution is that it will consume a lot of Gas fees, which is a rich and willful way of playing. Block burning generally considers the start time, each Tx interval, the number of sending times, gas costs, etc. This is generally considered by everyone based on the project time, monitoring pending tx, and the speed of block generation on the chain.
When Lengtu public sale snapped up, a large number of scientists used the method of burning blocks to snap up successfully. You can examine this wallet
How to prevent scientists
< p>
With the emergence of scientists’ panic buying, more and more projects have begun to use various methods to prevent scientists from panic buying. The essence of these methods is to restrict scientists from directly Call the contract mint, so that the person selected by the project party can mint
1. Only through the white list
All project sales use the whitelist mechanism, so that the project party can filter out the Someone who really appreciates the project.
But if there are rules, there will be countermeasures, level + number of invitations, chatbots and jobs will appear Shiyang account sells invited heads; creative art appears on Taobao to find people to paint on behalf of; now it has developed to invite people to Discord for a limited time; let everyone guess riddles and do tasks and other playing methods.
The project party is a studio that racks its brains and whitelists to fight wits and courage, ordinary NFT players He was also played around by various rules.
2. Public sale adopts capital verification lottery draw
< /p>For example, when NFT is sold to the public, a certain amount of ETH is required to verify the wallet in advance, and then the winning list will be given through the system lottery. However, many project parties are unwilling to make a 1:1 lottery system to save trouble. In the end, the public sale list was greatly oversold, and everyone rushed to buy it.
3. Signature verification mint on the server
< /p>Similar to the recent hot HAPE approach, the public NFT contract is limited to only a private closed-source contract to mint. After the closed-source contract, the backend server of the project side interacts. Technically speaking, this solution still follows the idea of web2 centralization and the idea of web3 decentralization seems to be a bit conflicting.
How will NFT develop in the future
Everyone who has passed the white list feels that now The NFT industry is very unhealthy, but the NFT industry is still in its early stages. If there is a problem, there will be someone in the market who will definitely come out to solve the problem.
NFT sales need to be public, notarized and transparent. I personally think that the solution can still be learned from everyone in real life Two familiar scenarios:
1. IPO, exchange account trading time, capital verification Wait for the threshold, and then draw a lottery for sale.
2. Jingdong Moutai snapped up, Jingdong platform conducts account authentication, snap-up fairness guarantee, etc.
p>These two scenarios ensure fairness through the authority of the platform, but there should be new solutions based on blockchain contracts in web3 to achieve similar functions, just like various trading protocols in the current DeFi market , there may be an NFT sale agreement in the near future, providing a fair, notarized and transparent sale model. I am still learning and thinking about how to do it specifically, and I welcome your guidance and discussion.
In the future, the NFT project party should be connected to an NFT launch platform, and the project party should focus more on art With the evolution of creation and roadmap, investors are more focused on the content and prospects of the project, and the launch platform solves various problems of NFT sales through technology.
Original link
Welcome to join the official BlockBeats community:
Telegram Subscription Group: https://t.me/theblockbeats
Telegram Discussion Group: https://t.me/BlockBeats_App
Official Twitter Account: https://twitter.com/BlockBeatsAsia