The EIP is a Redeemable NFT extension which adds a redeem function to EIP-721. It can be implemented when an NFT issuer wants his/her NFT to be redeemed for a physical object.
Motivation
An increasing amount of NFT issuers such as artists, fine art galeries, auction houses, brands and others want to offer a physical object to the holder of a given NFT. This standard allows EIP-721 NFTs to signal reedemability.
Specification
The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119.
EIP-721 compliant contracts MAY implement this EIP to provide a standard method of receiving information on redeemability.
The NFT issuer MUST decide who is allowed to redeem the NFT, and restrict access to the redeem() function accordingly.
Anyone MAY access the isRedeemable() function to check the redeemability status: it returns true when the NFT redeemable, and false when already redeemed.
Third-party services that support this standard MAY use the Redeem event to listen to changes on the redeemable status of the NFT.
Implementers of this standard MUST have all of the following functions:
import'@openzeppelin/contracts/utils/introspection/ERC165.sol';/**
* @dev Implementation of Redeemable for ERC-721s
*
*/interfaceIRedeemableisERC165{/*
* ERC165 bytes to add to interface array - set in parent contract implementing this standard
*
* bytes4 private constant _INTERFACE_ID_ERC721REDEEM = 0x2f8ca953;
*//// @dev This event emits when a token is redeemed.
eventRedeem(addressindexedfrom,uint256indexedtokenId);/// @notice Returns the redeem status of a token
/// @param tokenId Identifier of the token.
functionisRedeemable(uint256_tokenId)externalviewreturns(bool);/// @notice Redeeem a token
/// @param tokenId Identifier of the token to redeeem
functionredeem(uint256_tokenId)external;}
The Redeem event is emitted when the redeem() function is called.
The supportsInterface method MUST return true when called with 0x2f8ca953.
Rationale
When the NFT contract is deployed, the isRedeemable() function returns true by default.
By default, the redeem() function visibility is public, so anyone can trigger it. It is RECOMMENDED to add a require to restrict the access:
require(ownerOf(tokenId)==msg.sender,"ERC721Redeemable: You are not the owner of this token");
After the redeem() function is triggered, isRedeemable() function returns false.
Redeem event
When the redeem() function is triggered, the following event MUST be emitted:
Here’s an example of an EIP-721 that includes the Redeemable extension:
contractERC721RedeemableisERC721,Redeemable{constructor(stringmemoryname,stringmemorysymbol)ERC721(name,symbol){}functionisRedeemable(uint256tokenId)publicviewvirtualoverridereturns(bool){require(_exists(tokenId),"ERC721Redeemable: Redeem query for nonexistent token");returnsuper.isRedeemable(tokenId);}functionredeem(uint256tokenId)publicvirtualoverride{require(_exists(tokenId),"ERC721Redeemable: Redeem query for nonexistent token");require(ownerOf(tokenId)==msg.sender,"ERC721Redeemable: You are not the owner of this token");super.redeem(tokenId);}functionsupportsInterface(bytes4interfaceId)publicviewoverride(ERC721,Redeemable)returns(bool){returnsuper.supportsInterface(interfaceId);}}