Created
April 11, 2023 07:01
-
-
Save ChristianOConnor/e159a7935c90a3da7ef874eac5e5c76e to your computer and use it in GitHub Desktop.
Whitelisted NFT contract template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.8.18; | |
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; | |
contract RandomSurfaceReachT1 is ERC721URIStorage { | |
struct WhitelistedNft { | |
uint256 nonce; | |
address from; | |
} | |
constructor() ERC721("NFT WHITELIST ONE", "NFT WHITELIST ONE"){} | |
function verify( | |
address signer, | |
WhitelistedNft memory nft, | |
bytes32 sigR, | |
bytes32 sigS, | |
uint8 sigV | |
) internal view returns (bool) { | |
require(signer != address(0), "INVALID_SIGNER"); | |
return | |
signer == | |
ecrecover( | |
toTypedMessageHash(hashMetaTransaction(nft)), | |
sigV, | |
sigR, | |
sigS | |
); | |
} | |
bytes32 private constant WHITELISTED_NFT_TYPEHASH = keccak256( | |
bytes( | |
"WhitelistedNft(uint256 nonce,address from)" | |
)); | |
function hashWhitelistedNft(WhitelistedNft memory nft) | |
internal | |
pure | |
returns (bytes32) | |
{ | |
return | |
keccak256( | |
abi. encode( | |
WHITELISTED_NFT_TYPEHASH, | |
nft.nonce, | |
nft.from | |
) | |
); | |
} | |
address whitelistAccout; | |
uint256 nonce; | |
function mint(bytes32 sigR, bytes32 sigS, uint8 sigV) { | |
WhitelistedNft memory nft = WhitelistedNft({ | |
nonce: nonce, | |
from: sender | |
}); | |
verify(whitelistAccout, nft, sigR, sigS, sigV); | |
nonce += 1; | |
// your mint logic here | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment