-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloonies.sol
78 lines (61 loc) · 2.16 KB
/
loonies.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// SPDX-License-Identifier: MIT
// ERC-721 Smart Contract for the Loonies NFT Collection
pragma solidity ^0.8.0;
import "hardhat/console.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
string constant tokenName = "Loonies";
string constant symbol = "LOON";
contract Loonies is ERC721Enumerable, Pausable, Ownable {
using Strings for uint256;
uint256 public maxTokens; // Should be 12000
uint256 public price; // Cost of each mint in ETH
string public baseTokenURI; // base uri of loonies assets
constructor(
uint256 _maxToken,
uint256 _price,
string memory _baseTokenURI
) ERC721("Loonies", "LOON") {
maxTokens = _maxToken;
price = _price;
baseTokenURI = _baseTokenURI;
}
function mintNft(address _to) public payable whenNotPaused {
uint256 id = totalSupply() + 1;
if (msg.sender != owner()) {
require(msg.value >= price, "Ether sent is not enough");
}
require(id <= maxTokens, "Exceeds maximum supply");
_safeMint(_to, id);
}
function burn(uint256 tokenId) public virtual {
require(
_isApprovedOrOwner(_msgSender(), tokenId),
"ERC721Burnable: caller is not owner nor approved"
);
_burn(tokenId);
}
function pause() public onlyOwner {
_pause();
}
function unpause() public onlyOwner {
_unpause();
}
function setPrice(uint256 _price) public onlyOwner {
price = _price;
}
function setBaseURI(string memory _baseTokenURI) public onlyOwner {
baseTokenURI = _baseTokenURI;
}
function withdraw(uint256 _amount) public payable onlyOwner {
require(payable(msg.sender).send(_amount));
}
function withdrawAll() public payable onlyOwner {
require(payable(msg.sender).send(address(this).balance));
}
function _baseURI() internal view override(ERC721) returns (string memory) {
return baseTokenURI;
}
}