Skip to main content

Getting Started

This guide will help you set up and deploy ERC721S for your subscription-based service.

Prerequisites​

  • Foundry framework installed
  • An Ethereum wallet with funds for deployment
  • Basic familiarity with Solidity and smart contracts

Installation​

Clone the repository and install dependencies:

git clone https://github.com/vorpalengineering/ERC721S.git
cd ERC721S
forge install

Build​

Compile the smart contracts:

forge build

Testing​

Run the test suite:

# Standard output
forge test

# Verbose output for debugging
forge test -vv

Deployment​

Deploy the contract with your desired configuration. The constructor accepts the following parameters:

ParameterTypeDescription
namestringToken collection name
symbolstringToken symbol
owneraddressContract owner address
pricePerSeconduint256Cost per second of subscription
minDurationuint256Minimum subscription duration in seconds
maxDurationuint256Maximum duration per purchase, in seconds
maxAccumulatedDurationuint256Limit on remaining time when extending an active subscription
fundsRecipientaddressAddress to receive subscription payments

The constructor enables native ETH payments. The owner can enable EIP-3009-compatible ERC20 tokens later with setTokenConfig. Prices use the payment token’s smallest unit.

Example Deployment​

// Deploy with:
// - Name: "My Subscription"
// - Symbol: "MYSUB"
// - Owner: deployer address
// - Price: 0.0001 ETH per day (~1.157e-9 per second)
// - Min duration: 1 day (86400 seconds)
// - Max duration: 365 days (31536000 seconds)
// - Funds recipient: deployer address

ERC721S subscription = new ERC721S(
"My Subscription",
"MYSUB",
msg.sender,
1157407407, // ~0.0001 ETH per day in wei per second
86400, // 1 day minimum
31536000, // 365 days maximum per purchase
63072000, // 730-day accumulated limit
msg.sender
);

The Solidity snippets belong inside a deployment script or calling contract; they are not standalone source files. The sample rate is rounded down to whole wei per second.

Subscribing Users​

Once deployed, users can subscribe by calling the subscribe() function with the appropriate payment:

// Get the cost for a 30-day subscription
uint256 cost = subscription.getSubscriptionCost(address(0), 30 days);

// Subscribe (sends ETH with the transaction)
subscription.subscribe{value: cost}(msg.sender, 30 days);

The token belongs to the specified subscription owner, which may differ from the payer. Payments normally go directly to fundsRecipient.

For ERC20 payments, use the authorization overload described in the API Reference.

Next Steps​

  • Review the API Reference for all available functions
  • Check the test files in the repository for more usage examples