-
Notifications
You must be signed in to change notification settings - Fork 1
/
trashpanda_erc1155.sol
81 lines (62 loc) · 2.23 KB
/
trashpanda_erc1155.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
79
80
81
// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
contract Trashpanda is ERC1155, Ownable {
using Strings for uint256;
bool public publicSaleActive;
uint256 public constant MAX_SUPPLY = 10;
uint public mintPrice = 0.01 ether;
uint256 private _tokenIds;
string[MAX_SUPPLY] private _tokenUris;
modifier whenPublicSaleActive() {
require(publicSaleActive, "Public sale is not active");
_;
}
constructor() ERC1155("https://www.trashpanda.racoon/metadata/{id}.json") {}
function addTokenUri(uint256 tokenId, string memory tokenUri) external onlyOwner {
_tokenUris[tokenId] = tokenUri;
}
function uri(uint256 _id) public view override returns (string memory) {
if (bytes(_tokenUris[_id]).length > 0) {
return _tokenUris[_id];
}
return string(super.uri(_id));
}
function startPublicSale()
external
onlyOwner
{
require(!publicSaleActive, "Public sale has already begun");
publicSaleActive = true;
}
function pausePublicSale() external onlyOwner whenPublicSaleActive {
publicSaleActive = false;
}
function mint(uint256 numNfts)
external
payable
whenPublicSaleActive
{
require(_tokenIds + numNfts <= MAX_SUPPLY, "Minting would exceed max supply");
require(numNfts > 0, "Must mint at least one NFT");
require(mintPrice * numNfts <= msg.value, "Ether value sent is not correct");
for (uint i = 0; i < numNfts; i++){
_mint(msg.sender, _tokenIds, 1, "");
_tokenIds += 1;
}
}
function mintTo(uint256 numNfts, address toAddress)
external
onlyOwner
whenPublicSaleActive
{
require(_tokenIds + numNfts <= MAX_SUPPLY, "Minting would exceed max supply");
require(numNfts > 0, "Must mint at least one NFT");
for (uint i = 0; i < numNfts; i++){
_mint(toAddress, _tokenIds, 1, "");
_tokenIds += 1;
}
}
}