Simple NFT minting smart contract / getting errors on Remix

Hi everyone,

I feel a bit stucked and I think there is an easy fix to my problem but I can't see it. Here is a NFT minting simple smart contract. The contract is working but I'm trying to add a price to the NFT but I keep getting the following error on Remix when trying to mint:

Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending?
execution reverted: Not enough ETH sent; check price! { "originalError": { "code": 3, "data": "0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000214e6f7420656e6f756768204554482073656e743b20636865636b2070726963652100000000000000000000000000000000000000000000000000000000000000", "message": "execution reverted: Not enough ETH sent; check price!" } }

Here is the main SC

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "@openzeppelin/contracts@4.5.0/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts@4.5.0/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts@4.5.0/access/Ownable.sol";
import "@openzeppelin/contracts@4.5.0/utils/Counters.sol";

contract MyToken is ERC721, ERC721URIStorage, Ownable {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIdCounter;

    uint public constant PRICE = 0.0001 ether;

    constructor() ERC721("MyToken", "MTK") {}

    function safeMint(address to, string memory uri) public payable virtual{

       require(msg.value >= PRICE, "Not enough ETH sent; check price!");


        uint256 tokenId = _tokenIdCounter.current();
        _safeMint(to, tokenId);
        _setTokenURI(tokenId, uri);

    // The following functions are overrides required by Solidity.

    function _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage) {

    function tokenURI(uint256 tokenId)
        override(ERC721, ERC721URIStorage)
        returns (string memory)
        return super.tokenURI(tokenId);

Thanks for your help

Are you sure you're sending enough Ether?

You are not sending enough ether.
Equal to your price constant. For example of you are minting only one token you have to send 0.0001, then since you didn't add a minting limit.
You have to multiply your minting price x the amount of token you want to mint.

Thank you! But how exactly do I send ether when using the minting function on Remix?

Send a screenshot so I can mark it out

Ok got it! It worked but what I don't understand is when I will call the mint function from the frontend, where do I set this "value" ? Thanks

You have to learn how to use etherjs or web3

1 Like