Hi! I'm trying to understand how is the pricing logic implemented in smart contracts, specifically ones that mint NFTs. I have two code examples:
Code to reproduce
/*
* Mint Dizzy Dragon NFTs, woo!
*/
function adoptDragons(uint256 numberOfTokens) public payable {
require(saleIsActive, "Sale must be active to adopt dragons");
require(numberOfTokens <= MAX_MINTS_PER_TXN, "You can only adopt 15 dragons at a time");
require(totalSupply() + numberOfTokens <= maxTokenSupply, "Purchase would exceed max available dragons");
require(mintPrice * numberOfTokens <= msg.value, "Ether value sent is not correct");
for(uint256 i = 0; i < numberOfTokens; i++) {
uint256 mintIndex = _tokenIdCounter.current() + 1;
if (mintIndex <= maxTokenSupply) {
_safeMint(msg.sender, mintIndex);
_tokenIdCounter.increment();
}
}
// If we haven't set the starting index, set the starting index block.
if (startingIndexBlock == 0) {
startingIndexBlock = block.number;
}
}
So there's a require
for the msg.value
, but why is there no further visible ethereum transfer? There's obviously a mintPrice
. Is it somehow handled by exchange platforms like OpenSea?
- Same goes for Bored Ape Yacht Club:
/**
* Mints Bored Apes
*/
function mintApe(uint numberOfTokens) public payable {
require(saleIsActive, "Sale must be active to mint Ape");
require(numberOfTokens <= maxApePurchase, "Can only mint 20 tokens at a time");
require(totalSupply().add(numberOfTokens) <= MAX_APES, "Purchase would exceed max supply of Apes");
require(apePrice.mul(numberOfTokens) <= msg.value, "Ether value sent is not correct");
for(uint i = 0; i < numberOfTokens; i++) {
uint mintIndex = totalSupply();
if (totalSupply() < MAX_APES) {
_safeMint(msg.sender, mintIndex);
}
}
// If we haven't set the starting index and this is either 1) the last saleable token or 2) the first token to be sold after
// the end of pre-sale, set the starting index block
if (startingIndexBlock == 0 && (totalSupply() == MAX_APES || block.timestamp >= REVEAL_TIMESTAMP)) {
startingIndexBlock = block.number;
}
}
There's even a "Ether value sent is not correct"
error message in both examples.
I know that unused gas is returned to the sender, so basically I'm trying to figure out where is that process happening.
Thanks in advance.