Skip to content

Instantly share code, notes, and snippets.

@dexXxed
Last active June 18, 2022 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dexXxed/93b9fd3484fc20fa4396a2ff4f6002a2 to your computer and use it in GitHub Desktop.
Save dexXxed/93b9fd3484fc20fa4396a2ff4f6002a2 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.15+commit.e14f2714.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "erc721a/contracts/ERC721A.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract contract_name is ERC721A, Ownable { // edit
string private baseURI = "ipfs://QmWcfsm9fkXWh3MxZkqfd2r54uXsTNgn7CAXoP7qqww7eb/"; // edit
uint256 public MAX_MINTS = 1;
uint256 public MAX_SUPPLY = 100;
uint256 public mintRate = 0.01 ether; // edit
uint256 public DateMintStart = 1659312000; // Mon Aug 01 2022 00:00:00 GMT+0000
uint256 public whitelistMintRate = 0.005 ether; // edit
uint256 public whitelistDateMintStart = 1656633600; // Fri Jul 01 2022 00:00:00 GMT+0000
mapping(address => bool) public whitelisted_addresses;
constructor() ERC721A("Contract Name", "CN") {} // edit
// function to buy 1 NFT
function purchase() external payable {
if (whitelisted_addresses[msg.sender]) {
require(block.timestamp >= whitelistDateMintStart, "You can only mint after whitelistDateMintStart!");
require(_numberMinted(msg.sender) + 1 <= MAX_MINTS, "Exceeded the limit");
require(totalSupply() + 1 <= MAX_SUPPLY, "Not enough tokens left");
require(msg.value >= whitelistMintRate, "Not enough ether sent");
// delete user from whitelisted_addresses mapping
whitelisted_addresses[msg.sender] = false;
_safeMint(msg.sender, 1);
} else {
require(block.timestamp >= whitelistDateMintStart, "You can only mint after DateMintStart!");
require(_numberMinted(msg.sender) + 1 <= MAX_MINTS, "Exceeded the limit");
require(totalSupply() + 1 <= MAX_SUPPLY, "Not enough tokens left");
require(msg.value >= mintRate, "Not enough ether sent");
_safeMint(msg.sender, 1);
}
}
// function to return correct tokenURI (mainly made for Opensea)
function tokenURI(uint256 tokenId) public view override returns (string memory) {
return string(abi.encodePacked(baseURI, Strings.toString(tokenId), ".json"));
}
// function can modify the MAX_SUPPLY (onlyOwner)
function setNewMaxSupply(uint256 _MAX_SUPPLY) public onlyOwner {
MAX_SUPPLY = _MAX_SUPPLY;
}
// function can modify baseURI (onlyOwner)
function setNewBaseURI(string memory _newbaseURI) public onlyOwner {
baseURI = _newbaseURI;
}
// function can modify mintRate (onlyOwner)
function setNewMintRate(uint256 _mintRate) public onlyOwner {
mintRate = _mintRate;
}
// function can modify DateMintStart (onlyOwner)
function setNewDateMintStart(uint256 _DateMintStart) public onlyOwner {
DateMintStart = _DateMintStart;
}
// function can modify whitelistMintRate (onlyOwner)
function setNewWhitelistMintRate(uint256 _whitelistMintRate) public onlyOwner {
whitelistMintRate = _whitelistMintRate;
}
// function can modify whitelistDateMintStart (onlyOwner)
function setNewWhitelistDateMintStart(uint256 _whitelistDateMintStart) public onlyOwner {
whitelistDateMintStart = _whitelistDateMintStart;
}
// function can mint the _quantity of NFTs to the owner() account (onlyOwner)
function mintQuantity(uint256 _quantity) public onlyOwner {
_safeMint(msg.sender, _quantity);
}
// function can add account to whitelisted_addresses mapping (onlyOwner)
function addUserToWhitelist(address _whitelistedAddress) public onlyOwner {
whitelisted_addresses[_whitelistedAddress] = true;
}
// function can add multiple accounts to whitelisted_addresses mapping (onlyOwner)
function addUsersToWhitelist(address[] memory _whitelistedAddresses) public onlyOwner {
for(uint whitelistedAddressIndex = 0; whitelistedAddressIndex < _whitelistedAddresses.length; whitelistedAddressIndex++) {
whitelisted_addresses[_whitelistedAddresses[whitelistedAddressIndex]] = true;
}
}
// function can delete account from whitelisted_addresses mapping (onlyOwner)
function deleteUserFromWhitelist(address _whitelistedAddress) public onlyOwner {
whitelisted_addresses[_whitelistedAddress] = false;
}
// function can delete multiple accounts from whitelisted_addresses mapping (onlyOwner)
function addUsersFromWhitelist(address[] memory _whitelistedAddresses) public onlyOwner {
for(uint whitelistedAddressIndex = 0; whitelistedAddressIndex < _whitelistedAddresses.length; whitelistedAddressIndex++) {
whitelisted_addresses[_whitelistedAddresses[whitelistedAddressIndex]] = false;
}
}
// function can send all the money on the contract to the owner() (onlyOwner)
function withdraw() external payable 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