ERC-5643 Subscription NFT extension standard (Subscription NFTs)
Stagnant · NFTs & multi-token · created 2022-09-10
A standard that adds expiration, renewal, and cancellation functionality to EIP-721 NFTs so they can be used as subscription-based memberships or service access passes.
Why it is needed
NFTs on the blockchain are generally designed so that ownership persists permanently, with no concept of expiration. As a result, even in cases that require recurring payments, such as community or event memberships or service access passes, a token remains valid forever once minted. Services like ENS (Ethereum Name Service), which require periodic domain renewal, have each implemented their own similar approach independently, but without a common standard, implementations differ from project to project, making it hard for users to check or manage all their subscriptions in one place. In addition, as secondary royalty revenue from NFT resales trends downward, creators have lacked a good way to convert membership or access NFTs into a subscription model for ongoing revenue.
What to implement
event SubscriptionUpdate(uint256 indexed tokenId, uint64 expiration);: An event emitted whenever a subscription's expiration changes. If the subscription is cancelled, the expiration value also becomes 0.function renewSubscription(uint256 tokenId, uint64 duration) external payable;: Renews the NFT's subscription by extending it by duration (in seconds). Fails if tokenId is not a valid NFT.function cancelSubscription(uint256 tokenId) external payable;: Cancels the NFT's subscription. Fails if tokenId is not a valid NFT.function expiresAt(uint256 tokenId) external view returns(uint64);: Returns the expiration date of the subscription. Fails if tokenId is not a valid NFT.function isRenewable(uint256 tokenId) external view returns(bool);: Returns whether the subscription is renewable. Fails if tokenId is not a valid NFT.
In depth
Designed as an EIP-721 extension
This standard is an extension that inherits EIP-721 as is and simply adds a set of subscription-related functions. The NFT itself represents ownership of the subscription, with no requirement to issue a separate fungible or additional token. Existing EIP-721-compatible wallets and marketplaces can transfer and trade this NFT without modification, while subscription-related logic is handled through separate functions.
Behavior rules for renewSubscription
renewSubscription(tokenId, duration) extends the subscription of the NFT specified by tokenId by duration (in seconds, uint64). It must fail if tokenId is not a valid NFT. This function can be implemented as external or public, and is declared payable so it can accept payment upon renewal. If the call changes the expiration, it must emit a SubscriptionUpdate event.
Behavior rules for cancelSubscription
cancelSubscription(tokenId) cancels the subscription for the specified NFT. It must fail if tokenId is not a valid NFT. It can be implemented as external or public, and is declared payable. When the subscription is cancelled, the expiration value must become 0, and a SubscriptionUpdate event must also be emitted with an expiration value of 0.
expiresAt and isRenewable
expiresAt(tokenId) returns the subscription's expiration as a uint64, and can be implemented as pure or view. It must fail if tokenId is invalid. isRenewable(tokenId) returns a bool indicating whether the subscription is renewable, and can likewise be implemented as pure or view; it must fail if tokenId is invalid. These two functions let users and applications check a subscription's expiration and renewability in a standardized way.
The SubscriptionUpdate event and supportsInterface
The SubscriptionUpdate event must be emitted whenever a subscription's expiration changes (including renewal and cancellation), carrying an indexed tokenId and the new expiration value. On cancellation, the expiration value must be set to 0. In addition, the supportsInterface method must return true when called with the value 0x8c65f84d, which other contracts or apps use to confirm support for this interface (IERC5643).
Reference implementation structure
The reference implementation (ERC5643.sol) inherits OpenZeppelin's ERC721 and implements IERC5643. Internally, it stores each token's expiration in a mapping(uint256 => uint64) private _expirations. renewSubscription checks that the caller is the owner or an approved account, then, if the expiration is 0, adds duration to the current block timestamp, or if an expiration already exists, adds duration to the existing expiration. However, if the subscription has already expired and is not renewable (isRenewable is false), it reverts. cancelSubscription deletes the mapping entry, setting the expiration to 0.
Proposal status
This ERC is in Stagnant status, meaning discussion is currently no longer progressing. Since it has not been finalized as a standard, details may change in the future or it may not be adopted at all.