-
Notifications
You must be signed in to change notification settings - Fork 14
/
Blockhash.sol
43 lines (36 loc) · 1.39 KB
/
Blockhash.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
//SPDX-License-Identifier: CC0
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "../BatchReveal.sol";
// This is just an example, do NOT use this contract in production as it can be exploited due to the fact that the last blockhash is known
contract BlockhashExample is ERC721, BatchReveal {
using Strings for uint256;
string public baseURI;
string public unrevealedURI;
constructor(string memory _baseURI, string memory _unrevealedURI)
ERC721("Mock NFT", "MNFT")
{
unrevealedURI = _unrevealedURI;
baseURI = _baseURI;
}
uint public totalSupply = 0;
function mint(uint amount) public {
require((totalSupply + amount) <= TOKEN_LIMIT, "limit reached");
for(uint i = 0; i<amount; i++){
_mint(msg.sender, totalSupply);
totalSupply++;
if(totalSupply >= (lastTokenRevealed + REVEAL_BATCH_SIZE)){
setBatchSeed(uint256(blockhash(block.number-1)));
}
}
}
function tokenURI(uint256 id) public view override returns (string memory) {
if(id >= lastTokenRevealed){
return unrevealedURI;
} else {
return string(abi.encodePacked(baseURI, getShuffledTokenId(id).toString()));
}
}
}