Skip to content

Instantly share code, notes, and snippets.

@dome
Created May 1, 2025 14:23
Show Gist options
  • Save dome/d63cb3533f27fb82f6a80e9eb2ebd98b to your computer and use it in GitHub Desktop.
Save dome/d63cb3533f27fb82f6a80e9eb2ebd98b to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./../lib/openzeppelin-contracts/contracts/token/ERC721/ERC721.sol";
import "./../lib/openzeppelin-contracts/contracts/access/Ownable.sol";
import "./../lib/openzeppelin-contracts/contracts/utils/Strings.sol";
contract BullMoonNFT is ERC721, Ownable {
uint256 public currentTokenId = 0;
uint256 public constant MAX_SUPPLY = 3500;
uint256 public mintPrice = 0.01 ether;
string private _baseTokenURI;
bool public mintingEnabled = false;
constructor(string memory baseURI) ERC721("BullMoon", "BMN") Ownable(msg.sender) {
_baseTokenURI = baseURI;
}
function mintNFT() public payable returns (uint256) {
require(mintingEnabled, "Minting is not enabled");
require(currentTokenId < MAX_SUPPLY, "Max supply reached");
require(msg.value >= mintPrice, "Not enough ETH to mint NFT");
currentTokenId++;
uint256 newItemId = currentTokenId;
_safeMint(msg.sender, newItemId);
return newItemId;
}
function _baseURI() internal view virtual override returns (string memory) {
return _baseTokenURI;
}
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(ownerOf(tokenId) != address(0), "ERC721: URI query for nonexistent token");
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0
? string(abi.encodePacked(baseURI, Strings.toString(tokenId), ".json"))
: "";
}
function setBaseURI(string memory baseURI) external onlyOwner {
_baseTokenURI = baseURI;
}
function setMintPrice(uint256 newPrice) external onlyOwner {
require(newPrice > 0, "Price must be greater than 0");
mintPrice = newPrice;
}
function toggleMinting(bool enabled) external onlyOwner {
mintingEnabled = enabled;
}
function withdraw() external onlyOwner {
payable(owner()).transfer(address(this).balance);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment