Skip to content

Commit

Permalink
smart contract test realese 1
Browse files Browse the repository at this point in the history
  • Loading branch information
MrRaccxxn committed Mar 7, 2022
0 parents commit d3580e6
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
artifacts
cache
node_modules

.env
package-lock.json
85 changes: 85 additions & 0 deletions contracts/LabPunks.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "erc721a/contracts/ERC721A.sol";

contract LabPunks is Ownable, ERC721A, ReentrancyGuard {
uint256 public constant MAX_SUPPLY = 1000;
uint256 public constant maxPerAddressDuringMint = 5;
bool public isPreSaleRunning = false;
bool public isPublicSaleRunning = false;
uint256 private _preSalePrice = 0.01 ether;
uint256 private _salePrice = 0.015 ether;
mapping(address => uint256) public preSaleList;

event NewMint(address indexed _from, uint256 _quantity);

constructor() ERC721A("LabPunks", "LP") {}

modifier callerIsUser() {
require(tx.origin == msg.sender, "The caller is another contract");
_;
}

function changePreSaleState(bool preSaleState) public onlyOwner {
isPreSaleRunning = preSaleState;
}

function changePublicSaleState(bool publicSaleState) public onlyOwner {
isPublicSaleRunning = publicSaleState;
}

function preSaleMint() external payable callerIsUser {
require(isPreSaleRunning);
require(preSaleList[msg.sender] > 0, "not eligible for allowlist mint");
require(totalSupply() + 1 <= MAX_SUPPLY, "reached max supply");
preSaleList[msg.sender]--;
_safeMint(msg.sender, 1);
emit NewMint(msg.sender, 1);
}

function mint(uint256 quantity) external payable callerIsUser{
require(isPublicSaleRunning);
require(totalSupply() + quantity <= MAX_SUPPLY, "reached max supply");
require(
numberMinted(msg.sender) + quantity <= maxPerAddressDuringMint,
"can not mint this many"
);
_safeMint(msg.sender, quantity);
emit NewMint(msg.sender, quantity);
}

function numberMinted(address owner) public view returns (uint256) {
return _numberMinted(owner);
}

function preSalelist(address[] memory addresses, uint256[] memory numSlots)
public
onlyOwner
{
require(
addresses.length == numSlots.length,
"addresses does not match numSlots length"
);
for (uint256 i = 0; i < addresses.length; i++) {
preSaleList[addresses[i]] = numSlots[i];
}
}

string private _baseTokenURI;

function _baseURI() internal view virtual override returns (string memory) {
return _baseTokenURI;
}

function setBaseURI(string calldata baseURI) external onlyOwner {
_baseTokenURI = baseURI;
}

function withdrawMoney() external onlyOwner nonReentrant {
(bool success, ) = msg.sender.call{value: address(this).balance}("");
require(success, "Transfer failed.");
}
}
12 changes: 12 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require('@nomiclabs/hardhat-waffle');
require('dotenv').config();

module.exports = {
solidity: '0.8.4',
networks: {
rinkeby: {
url: process.env.STAGING_ALCHEMY_KEY,
accounts: [process.env.PRIVATE_KEY],
},
},
};
25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "ERC721-implementation",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@openzeppelin/contracts": "^4.4.2",
"dotenv": "^15.0.0"
},
"devDependencies": {
"erc721a": "^2.2.0",
"@nomiclabs/hardhat-ethers": "^2.0.4",
"@nomiclabs/hardhat-waffle": "^2.0.2",
"chai": "^4.3.6",
"ethereum-waffle": "^3.4.0",
"ethers": "^5.5.3",
"hardhat": "^2.8.3"
}
}
18 changes: 18 additions & 0 deletions scripts/deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const main = async () => {
const nftContractFactory = await hre.ethers.getContractFactory('LabPunks');
const nftContract = await nftContractFactory.deploy();
await nftContract.deployed();
console.log("Contract deployed to:", nftContract.address);
};

const runMain = async () => {
try {
await main();
process.exit(0);
} catch (error) {
console.log(error);
process.exit(1);
}
};

runMain();

0 comments on commit d3580e6

Please sign in to comment.