I attempting to implement an NFT minter into my application, but want to set prices for minting an NFT. I'm using a smart contract template I found but haven't been able to figure out how to set prices. I've seen similar solutions for a smart contract that is like mine, but I can't seem to get prices to be set correctly.
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
contract HiddenInPlainSight is ERC721, ERC721Enumerable, ERC721URIStorage {
using SafeMath for uint256;
uint public constant mintPrice = (4 ether/10);
function _beforeTokenTransfer(address from, address to, uint256 tokenId)
internal
override(ERC721, ERC721Enumerable)
{
super._beforeTokenTransfer(from, to, tokenId);
}
function _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage) {
super._burn(tokenId);
}
function tokenURI(uint256 tokenId)
public
view
override(ERC721, ERC721URIStorage)
returns (string memory)
{
return super.tokenURI(tokenId);
}
function supportsInterface(bytes4 interfaceId)
public
view
override(ERC721, ERC721Enumerable)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
constructor() ERC721("Hidden In Plain Sight", "TLJ") {}
function mint(string memory _uri) public payable {
uint256 mintIndex = totalSupply();
require(msg.value == mintPrice, "Provide more ETH");
_safeMint(msg.sender, mintIndex);
_setTokenURI(mintIndex, _uri);
}
}
I added a require statement in the mint function but when I try to call the function, the transaction fails. Any ideas?