forked from DeltaVThrust-NFT/merkletreejs-nft-whitelist
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWhitelistSale.sol
27 lines (22 loc) · 889 Bytes
/
WhitelistSale.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
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
contract WhitelistSale is ERC721 {
bytes32 immutable public merkleRoot;
uint256 public nextTokenId;
mapping(address => bool) public claimed;
constructor(bytes32 _merkleRoot) ERC721("ExampleNFT", "NFT") {
merkleRoot = _merkleRoot;
}
function toBytes32(address addr) pure internal returns (bytes32) {
return bytes32(uint256(uint160(addr)));
}
function mint(bytes32[] calldata merkleProof) public payable {
require(claimed[msg.sender] == false, "already claimed");
claimed[msg.sender] = true;
require(MerkleProof.verify(merkleProof, merkleRoot, toBytes32(msg.sender)) == true, "invalid merkle proof");
nextTokenId++;
_mint(msg.sender, nextTokenId);
}
}