Set a Mint Price on Your NFT Smart Contract

Ryan Harris
InstructorRyan Harris
Share this video with your friends

Social Share Links

Send Tweet
Published 2 years ago
Updated 2 years ago

We want to actually sell our NFT tickets, so let’s set a mint price.

In our smart contract, we can just set the price to an integer variable. We’ll then make our mint function payable. When a function is payable in Solidity it means it can receive ether.

Once our mint function is payable, we can call the require function to check if the initiator of the function is sending enough ether.

Instructor: [0:00] Now let's set a mint price for the NFT tickets that we're selling through the smart contract. The first thing we're going to do is come down here and add another integer to our contract state, uint256 public mintPrice equals -- and I'm going to paste this -- 80000000000000000.

[0:21] While our NFTs will be sold for .08 ETH, this value is in Gwei. You can think of this like dollars and cents, and read more about it in the Etherium documentation.

[0:33] Now that we've set the price, let's come down to our mint function again. After public, we'll add the payable keyword. This means this function can receive Ether. Inside the function, we'll add another require statement.

[0:47] This time, we're going to check that we're receiving enough Ether to mint an NFT. We'll check that msg.value is greater than or equal to our current mint price. If not, we'll log out, "Not enough ETH."

[1:01] Then we can redeploy the smart contract to our local blockchain by running yarn deploy. Let's hop over to our browser. We'll come down to our mint function here. You can see the UI has changed a bit.

[1:14] We now have an input next to the mint function which allows us to send Ether when minting a new NFT. We also have a value for mint price of .08 ETH, which indicates how much we need to send when minting a new token. We'll come up here. We'll type .08.

[1:32] Hit the asterisk button to convert it to Gwei, and then click Send. You can see we've successfully minted a new NFT. To prove out that the smart contract is enforcing the mint price, let's come up here and change the value to something less like .04 ETH.

[1:49] We'll convert that to Gwei, and then we'll send the transaction. You can see here it failed and we have a message, not enough ETH. To review, we've added a new integer to the contract state called mint price.

[2:06] Below, we've also added the payable keyword to the mint function, meaning it can receive Ether. Inside the function, we've added a new require statement which confirms we've received enough Ether to mint an NFT.

~ 4 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today