Skip to content

Instantly share code, notes, and snippets.

@dexXxed
Last active June 28, 2022 12:23
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/14bb591cd9daf6bedc00b13377bd7f95 to your computer and use it in GitHub Desktop.
Save dexXxed/14bb591cd9daf6bedc00b13377bd7f95 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.4+commit.c7e474f2.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "erc721a/contracts/ERC721A.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
contract Condominos is ERC721A, Ownable {
string public baseURI = "ipfs://QmdqYRggJzkgAtkJAcY2NM9ZjDtZZSLLo6inCAMdRSCrEu/";
uint256 public MAX_TOTAL_SUPPLY = 1000;
uint256 public MaxMintRegular = 5;
uint256 public mintRateRegular = 0.05 ether;
uint256 public MaxMintWhitelist = 5;
uint256 public mintRateWhitelist = 0.000555 ether;
uint256 public timeToStartSales = 1656115200; // Sat Jun 25 2022 00:00:00 GMT+0000
uint256 public timeToStartSalesWhitelisted = 1656201600; // Sun Jun 26 2022 00:00:00 GMT+0000
// Whitelist mapping
mapping(address => bool) public whitelisted_addresses;
constructor() ERC721A("Condominos", "CNDMNS") {
_safeMint(msg.sender, 445); // mints 445 Condominos to admin account
}
// function to buy _quantity Condominos NFTs
function purchase(uint256 _quantity) external payable {
require(block.timestamp >= timeToStartSales, "You can mint only after timeToStartSales!");
require(_numberMinted(msg.sender) + _quantity <= MaxMintRegular, "Exceeded the address limit");
require(totalSupply() + _quantity <= MAX_TOTAL_SUPPLY, "Not enough tokens left");
// if address is whitelisted
if (whitelisted_addresses[msg.sender]) {
require(block.timestamp >= timeToStartSalesWhitelisted, "You can mint only after timeToStartSalesWhitelisted!");
require(msg.value >= mintRateWhitelist * _quantity, "Not enough ether sent");
// delete user from whitelisted_addresses mapping
whitelisted_addresses[msg.sender] = false;
_safeMint(msg.sender, _quantity);
} else {
require(msg.value >= mintRateRegular * _quantity, "Not enough ether sent");
_safeMint(msg.sender, _quantity);
}
}
// function to set new MAX_TOTAL_SUPPLY (onlyOwner)
function setNewMaxTotalSupply(uint256 _MAX_TOTAL_SUPPLY) public onlyOwner {
MAX_TOTAL_SUPPLY = _MAX_TOTAL_SUPPLY;
}
// function to set new MaxMintRegular (onlyOwner)
function setNewMaxMintRegular(uint256 _MaxMintRegular) public onlyOwner {
MaxMintRegular = _MaxMintRegular;
}
// function to set new mintRateRegular (onlyOwner)
function setNewMintRateRegular(uint256 _mintRateRegular) public onlyOwner {
mintRateRegular = _mintRateRegular;
}
// function to set new MaxMintWhitelist (onlyOwner)
function setnewMaxMintWhitelist(uint256 _MaxMintWhitelist) public onlyOwner {
MaxMintWhitelist = _MaxMintWhitelist;
}
// function to set new mintRateWhitelist (onlyOwner)
function setNewMintRateWhitelist(uint256 _mintRateWhitelist) public onlyOwner {
mintRateWhitelist = _mintRateWhitelist;
}
// function to set new timeToStartSales (onlyOwner)
function setNewTimeToStartSales(uint256 _timeToStartSales) public onlyOwner {
timeToStartSales = _timeToStartSales;
}
// function to set new timeToStartSalesWhitelisted (onlyOwner)
function setNewTimeToStartSalesWhitelisted(uint256 _timeToStartSalesWhitelisted) public onlyOwner {
timeToStartSalesWhitelisted = _timeToStartSalesWhitelisted;
}
// function can add account to whitelisted_addresses mapping (onlyOwner)
function addUserToWhitelist(address _whitelistedAddress) public onlyOwner {
whitelisted_addresses[_whitelistedAddress] = true;
}
// function can delete account from whitelisted_addresses mapping (onlyOwner)
function deleteUserFromWhitelist(address _whitelistedAddress) public onlyOwner {
whitelisted_addresses[_whitelistedAddress] = false;
}
// 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 multiple accounts from whitelisted_addresses mapping (onlyOwner)
function deleteUsersFromWhitelist(address[] memory _whitelistedAddresses) public onlyOwner {
for(uint whitelistedAddressIndex = 0; whitelistedAddressIndex < _whitelistedAddresses.length; whitelistedAddressIndex++) {
whitelisted_addresses[_whitelistedAddresses[whitelistedAddressIndex]] = false;
}
}
// function can mint the _quantity of NFTs to the owner() account (onlyOwner)
function mintQuantity(uint256 _quantity) public onlyOwner {
require(totalSupply() + _quantity <= MAX_TOTAL_SUPPLY, "Not enough tokens left");
_safeMint(msg.sender, _quantity);
}
// function can send all the money from the contract to the owner() (onlyOwner)
function withdraw() external payable onlyOwner {
payable(owner()).transfer(address(this).balance);
}
// function can modify baseURI (onlyOwner)
function setNewBaseURI(string memory _newbaseURI) public onlyOwner {
baseURI = _newbaseURI;
}
// 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 + 1), ".json"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment