-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathContract.sol
68 lines (57 loc) · 2.07 KB
/
Contract.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
// SPDX-License-Identifier: MIT
pragma solidity 0.8.10;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract MyNFT is ERC721, ERC721Enumerable, Ownable {
enum Color {Black, White, Purple, Cyan, Yellow, Orange}
uint public SUPPLY;
uint public MAX_SUPPLY = 66;
uint public PRICE = 4 ether;
mapping (uint=>Color) public token_color;
mapping (Color=>string) public color_uri;
constructor() ERC721("OG Filosofia Codigo", "OGFC") {}
function tokenURI(uint256 token_id) public view virtual override returns (string memory) {
require(_exists(token_id), "ERC721Metadata: URI query for nonexistent token");
return color_uri[token_color[token_id]];
}
function setTokenURIs(string[] memory uris) public onlyOwner
{
color_uri[Color.Black] = uris[0];
color_uri[Color.White] = uris[1];
color_uri[Color.Purple] = uris[2];
color_uri[Color.Cyan] = uris[3];
color_uri[Color.Yellow] = uris[4];
color_uri[Color.Orange] = uris[5];
}
function setTokenColor(uint token_id, Color color) public
{
require(msg.sender == ownerOf(token_id), "Must be token owner.");
token_color[token_id] = color;
}
function mint() public payable
{
require(msg.value >= PRICE, "Must pay price.");
require(SUPPLY < MAX_SUPPLY, "Max supply must not be reached.");
_mint(msg.sender, SUPPLY);
SUPPLY += 1;
}
function withdraw() public
{
(bool sent, bytes memory data) = address(owner()).call{value: address(this).balance}("");
require(sent, "Failed to send Ether");
data;
}
function setPrice(uint _price) public onlyOwner
{
PRICE = _price;
}
function supportsInterface(bytes4 interfaceId) public view override(ERC721, ERC721Enumerable) returns (bool)
{
return super.supportsInterface(interfaceId);
}
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal override(ERC721, ERC721Enumerable)
{
super._beforeTokenTransfer(from, to, tokenId);
}
}