'How to attach price to NFT mint?

I am having a little trouble with attaching a price to my NFT contract. After deploying, I am testing by sending the contract the amount, but it does not look like the contract is saving/retaining the sent amount because the contract balance stays at 0.

Is there some keyword that I need for the contract to accept/take the .value from the transaction? The relevant part of my mint function is here:

// reconcile payments

bool sent = payable(owner()).send(tokenPrice);

require(sent, "failed to send ether");

if (msg.value - tokenPrice > 0) {

payable(msg.sender).transfer(msg.value - tokenPrice);

}

Also, I am having trouble adding a price to the transaction from the website. Is this something that should be done on the client side with ethers.js?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source