Created
September 14, 2021 22:00
-
-
Save axic/ac353f2475fd4a07dadf02a8f1187932 to your computer and use it in GitHub Desktop.
ReedemableNFT, where a curator can issue a redeemable cheque for minting a given token.
This file contains 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
// ReedemableNFT, where a curator can issue a redeemable cheque for minting a given token. | |
// | |
// The message to be signed is an EIP-712 compatible structured data: | |
// struct RedeemableNFT { | |
// address recipient; | |
// uint256 tokenId; | |
// } | |
// | |
// This message can then signed by the curator and given to the user who submits it. | |
// The validity of the signature is checked according to EIP-1271 if the signer is a contract, | |
// or via a regular signature check otherwise. | |
// | |
// See: https://eips.ethereum.org/EIPS/eip-712 and https://eips.ethereum.org/EIPS/eip-1271 | |
// | |
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
import "@openzeppelin/contracts/access/Ownable.sol"; | |
import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | |
import "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol"; | |
import "@openzeppelin/contracts/utils/cryptography/draft-EIP712.sol"; | |
abstract contract RedeemableNFT is ERC721, EIP712, Ownable { | |
bytes32 private constant REDEEMABLENFT_TYPEHASH = keccak256("RedeemableNFT(address recipient, uint256 tokenId)"); | |
constructor(string memory name, string memory symbol) ERC721(name, symbol) EIP712(name, "1") {} | |
function redeemCheque(address recipient, uint256 tokenId, bytes memory signature) external { | |
bytes32 digest = _hashTypedDataV4(keccak256(abi.encode( | |
REDEEMABLENFT_TYPEHASH, | |
recipient, | |
tokenId | |
))); | |
require(SignatureChecker.isValidSignatureNow(owner(), digest, signature), "RedeemableNFT: Invalid signature"); | |
_mint(recipient, tokenId); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment