Skip to main content

API Reference

Complete reference for all ERC721S functions and parameters.

State Variables

VariableTypeDescription
pricePerSeconduint256Cost per second of subscription in wei
minSubscriptionDurationuint256Minimum purchasable subscription period in seconds
maxSubscriptionDurationuint256Maximum purchasable subscription period in seconds
fundsRecipientaddressAddress that receives subscription payments

User Functions

subscribe

Creates a new subscription or extends an existing one.

function subscribe(uint256 duration) external payable

Parameters:

  • duration - Subscription duration in seconds

Requirements:

  • duration must be between minSubscriptionDuration and maxSubscriptionDuration
  • msg.value must equal getSubscriptionCost(duration)

Behavior:

  • If the caller has no token, mints one with ID derived from their address
  • If subscription is expired, sets new expiration to block.timestamp + duration
  • If subscription is active, extends expiration by duration

View Functions

getSubscriptionCost

Calculates the cost for a given subscription duration.

function getSubscriptionCost(uint256 duration) public view returns (uint256)

Parameters:

  • duration - Subscription duration in seconds

Returns:

  • Cost in wei

deriveTokenId

Computes the token ID for a given address.

function deriveTokenId(address user) public pure returns (uint256)

Parameters:

  • user - User address

Returns:

  • Token ID (derived from address)

hasActiveSubscription

Checks if an address has an active subscription.

function hasActiveSubscription(address user) public view returns (bool)

Parameters:

  • user - User address to check

Returns:

  • true if the user has an active (non-expired) subscription

isSubscriptionActive

Checks if a specific token has an active subscription.

function isSubscriptionActive(uint256 tokenId) public view returns (bool)

Parameters:

  • tokenId - Token ID to check

Returns:

  • true if the subscription is not expired

Owner Functions

setPrice

Updates the price per second for subscriptions.

function setPrice(uint256 newPricePerSecond) external onlyOwner

Parameters:

  • newPricePerSecond - New price in wei per second

setFundsRecipient

Updates the address that receives subscription payments.

function setFundsRecipient(address newRecipient) external onlyOwner

Parameters:

  • newRecipient - New recipient address

withdraw

Withdraws all ETH from the contract to the funds recipient.

function withdraw() external onlyOwner

Events

Subscribed

Emitted when a user subscribes or extends their subscription.

event Subscribed(address indexed user, uint256 indexed tokenId, uint256 expiration)

Security Considerations

  • The contract uses OpenZeppelin's ReentrancyGuard to prevent reentrancy attacks during payment handling
  • Ownership transfers use Ownable2Step requiring explicit acceptance to prevent accidental transfers
  • Token transfers are disabled (non-transferable tokens)