Skip to main content

SubscriptionGatedNFT

Inherits: ERC721

Title: SubscriptionGatedNFT

Author: amser

ERC721 that mirrors subscription state via an external authorization module. Each address may hold at most one token and minting is gated by active subscription status for the configured planId.

This contract intentionally avoids burn and upgrade hooks. Token metadata is derived dynamically from the authorization module; no subscription state is stored locally.

State Variables

authorizationModule

External authorization module used to verify subscription status.

address public immutable authorizationModule

planId

Subscription plan enforced for gating logic.

uint256 public immutable planId

activeURI

Token metadata URI returned for active subscribers.

string public activeURI

expiredURI

Token metadata URI returned for expired or inactive subscribers.

string public expiredURI

_nextTokenId

Incremental token ID counter (1-based to leverage 0 as sentinel).

uint256 private _nextTokenId = 1

Functions

constructor

constructor(
address _authorizationModule,
uint256 _planId,
string memory _activeURI,
string memory _expiredURI
)
ERC721("Subscription Gated NFT", "SUBNFT");

mint

Mint a token to the caller if they have an active subscription.

Each address may hold at most one token. Subscription status is resolved via the configured authorization module; no state is cached.

function mint() external;

tokenURI

Returns metadata URI based on the current subscription status of the token owner.

No subscription state is stored locally; subscription validity is pulled from the authorization module on demand.

function tokenURI(uint256 tokenId) public view override returns (string memory);

_update

function _update(address to, uint256 tokenId, address auth)
internal
override
returns (address);

Errors

NOT_ACTIVE_SUBSCRIBER

Thrown when minting without an active subscription.

error NOT_ACTIVE_SUBSCRIBER();

ALREADY_OWNS_TOKEN

Thrown when attempting to mint or receive more than one token.

error ALREADY_OWNS_TOKEN();

BURN_DISABLED

Thrown when attempting to burn (disabled by design).

error BURN_DISABLED();