API Reference
Complete reference for all ERC721S functions and parameters.
State Variables
| Variable | Type | Description |
|---|---|---|
pricePerSecond | uint256 | Cost per second of subscription in wei |
minSubscriptionDuration | uint256 | Minimum purchasable subscription period in seconds |
maxSubscriptionDuration | uint256 | Maximum purchasable subscription period in seconds |
fundsRecipient | address | Address 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:
durationmust be betweenminSubscriptionDurationandmaxSubscriptionDurationmsg.valuemust equalgetSubscriptionCost(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:
trueif 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:
trueif 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
ReentrancyGuardto prevent reentrancy attacks during payment handling - Ownership transfers use
Ownable2Steprequiring explicit acceptance to prevent accidental transfers - Token transfers are disabled (non-transferable tokens)