A decentralized subscription platform built with Solidity, Next.js, React, Ethers.js, Wagmi, and RainbowKit.
The platform allows creators to create subscription plans and users to purchase subscriptions using ETH. Each active subscription is represented by an ERC-721 NFT, which acts as an on-chain proof of the user's subscription.
- Create a creator profile with a unique username
- Create multiple subscription plans
- Set the price and duration for each plan
- Activate or deactivate subscription plans
- View creator balance
- Withdraw earned ETH
- Track the number of subscribers
- Connect a Web3 wallet
- Browse available creators
- View creator subscription plans
- Purchase a subscription using ETH
- Renew subscriptions
- Gift a subscription to another address
- Receive an NFT representing the subscription
- Check whether a subscription is currently active
- Creator management
- Subscription plan management
- Subscription payments in ETH
- Subscription expiry tracking
- Subscription renewal
- Subscription gifting
- Creator withdrawals
- Platform fee collection
- Contract pause/resume functionality
- Reentrancy protection
- Custom Solidity errors
- On-chain events
- ERC-721 subscription NFTs
The basic flow is:
User
│
│ Connect Wallet
▼
Next.js Frontend
│
│ Contract Interaction
▼
Subscription Contract
│
├── Creator Management
├── Subscription Plans
├── ETH Payments
├── Subscription Expiry
└── Platform Fees
│
▼
SubscriptionNFT Contract
│
└── ERC-721 Subscription NFT
When a user purchases a subscription:
- The user selects a creator and subscription plan.
- The frontend sends the required ETH to the
Subscriptioncontract. - The contract verifies the creator, plan, price, and subscription state.
- The subscription expiry timestamp is calculated.
- A platform fee is deducted.
- The remaining amount is credited to the creator.
- The
SubscriptionNFTcontract mints an NFT for the user. - The NFT stores the creator, subscriber, and expiry information.
- The subscription can later be checked directly on-chain.
The main contract responsible for the subscription system.
It manages:
- Creators
- Creator profiles
- Subscription plans
- Subscription purchases
- Subscription renewals
- Gift subscriptions
- Creator balances
- Platform fees
- Subscription validation
- Contract administration
Important functions include:
addCreator()
removeCreator()
setCreatorData()
addPlan()
activatePlan()
deactivatePlan()
buyOrRenewSubscription()
giftSubscription()
creatorWithdraw()
isValidSubscription()
collectFee()
pauseContract()
resumeContract()The contract also uses OpenZeppelin's Ownable and ReentrancyGuard.
An ERC-721 contract used to represent subscriptions as NFTs.
Each subscription NFT stores:
struct NFT {
address creator;
address user;
uint expiry;
}The NFT contract supports:
- Minting subscription NFTs
- Renewing existing subscription NFTs
- Checking subscription validity
- Reading subscription expiry
A user receives one NFT per creator. Renewing the subscription updates the existing NFT's expiry rather than minting another NFT.
The platform charges a configurable fee whenever a subscription is purchased.
The contract stores the fee in basis points:
feeAPYFor example:
200 = 2%
500 = 5%
1000 = 10%
The maximum fee is limited to 10%.
The payment is split into:
Subscription Payment
│
├── Platform Fee
│
└── Creator Balance
Creators can withdraw their accumulated balance, while the contract owner can collect the accumulated platform fees.
- Next.js
- React
- TypeScript
- Tailwind CSS
- Lucide React
- React Hot Toast
- Solidity
- Ethers.js
- Wagmi
- Viem
- RainbowKit
- Solidity
^0.8.20 - OpenZeppelin Contracts
- ERC-721
- Ownable
- ReentrancyGuard
The current package.json confirms the frontend dependencies include Next.js, React, Ethers.js, Wagmi, Viem, RainbowKit, and Tailwind CSS.
Subscription-dapp/
│
├── contracts/
│ ├── subscription.sol
│ └── subscriptionNFT.sol
│
├── public/
│
├── src/
│ ├── app/
│ ├── components/
│ ├── config/
│ ├── hooks/
│ ├── utils/
│ ├── providers.tsx
│ └── wagmi.ts
│
├── package.json
├── next.config.ts
├── postcss.config.mjs
├── tsconfig.json
└── README.md
The repository separates the Solidity contracts under contracts/ and the Next.js application under src/.
Make sure you have installed:
- Node.js
- npm
- Git
- MetaMask or another compatible Web3 wallet
git clone https://github.com/mohit-solidity/Subscription-dapp.git
cd Subscription-dappnpm installnpm run devThen open:
http://localhost:3000
npm run devStarts the Next.js development server.
npm run buildCreates a production build.
npm run startStarts the production server.
npm run lintRuns ESLint.
This project is intended primarily as a learning and development project.
The contracts use several OpenZeppelin security primitives, including:
Ownablefor administrative access controlReentrancyGuardfor withdrawal protection- Solidity custom errors
- Checks before transferring ETH
- Contract pause functionality
However, the contracts have not been professionally audited.
Do not use the contracts with real funds without conducting a complete security review and audit.
This project demonstrates several important Web3 development concepts:
- Solidity smart contract architecture
- Contract-to-contract interaction
- ERC-721 NFTs
- ETH payments
- Subscription expiry using
block.timestamp - Access control
- Reentrancy protection
- Custom errors
- Solidity events
- React + Web3 integration
- Wallet connection
- Contract reads and writes
- Transaction handling
- On-chain state management
Potential improvements include:
- Automatic subscription renewal
- Stablecoin payments
- More flexible billing periods
- Subscription cancellation/refunds
- Creator analytics
- Subscription history
- NFT metadata
- Multi-chain support
- Better gas optimization
- Comprehensive Foundry tests
- Smart contract security audit
- Decentralized metadata storage
This project is for educational and experimental purposes.
The smart contracts have not been professionally audited. Use at your own risk and do not deposit funds that you cannot afford to lose.
Mohit Sharma
Blockchain Developer | Solidity • React.js • Ethers.js
GitHub: https://github.com/mohit-solidity
Repository: https://github.com/mohit-solidity/Subscription-dapp