Skip to content

A decentralized recurring payment protocol on Solana built with Anchor, Rust, and Next.js. Features trustless escrow vaults and time-locked billing

License

Notifications You must be signed in to change notification settings

raushan728/solana-subscription-system

Repository files navigation

Solana Subscription Protocol

Solana Devnet Anchor Framework Rust TypeScript Next.js License

Table of Contents

Introduction

The Solana Subscription Protocol is a decentralized, trustless recurring payment system built on the Solana Blockchain. It enables users to subscribe to services using a secure, on-chain Pull-Payment Model. Unlike traditional Web2 subscriptions, this protocol ensures that funds are locked in Program Derived Address (PDA) vaults and can only be withdrawn by the provider according to the agreed-upon billing cycle. Users retain full control to cancel their subscriptions at any time, preventing future charges.

Project Demo

Below are screenshots demonstrating the user interface and functionality of the subscription system.

Dashboard View Subscription Management
Dashboard Subscription
Transaction Details
Transaction

Features

  • Trustless Vaults: User funds are secured in Program Derived Addresses (PDAs), ensuring no single party has unilateral control.
  • Time-Locked Release: Service providers can only withdraw funds after the specific billing period has elapsed.
  • User-Controlled Cancellation: Users can cancel subscriptions instantly, stopping all future payments.
  • Interactive Dashboard: A modern Next.js interface for wallet connection, subscription tracking, and management.
  • Transparent Logic: All payment rules are enforced by immutable on-chain smart contracts.

Architecture

The system utilizes the Anchor Framework to manage state via three primary account types:

Account Type Seed Structure Description
PlanAccount ["plan", owner_pubkey] Defines subscription terms, including price and duration.
SubscriptionAccount ["subscription", user, plan] Records user status and the next valid billing timestamp.
VaultAccount ["vault", plan_pubkey] A secure escrow account holding the subscribed funds.

Tech Stack

  • Blockchain: Solana Devnet
  • Smart Contract: Rust, Anchor Framework (v0.30+)
  • Client SDK: TypeScript, Anchor.js, Web3.js
  • Frontend: Next.js (App Router), Tailwind CSS, Framer Motion
  • Wallet Integration: Solana Wallet Adapter

Getting Started

Prerequisites

Prerequisites

You need to have the following tools installed. Follow the instructions for your operating system.

Linux / macOS / Windows (WSL2)

Note for Windows Users: Solana development on Windows is strongly recommended to be done via WSL2 (Windows Subsystem for Linux). Native Windows support is limited.

  1. Install WSL2 (Windows Only): Open PowerShell as Administrator and run:

    wsl --install

    Restart your computer if prompted, then launch "Ubuntu" from the Start menu.

  2. Rust & Cargo:

    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  3. Solana CLI:

    curl --proto '=https' --tlsv1.2 -sSfL https://solana-install.solana.workers.dev | bash
  4. Anchor CLI (via avm):

    cargo install --git https://github.com/coral-xyz/anchor avm --locked --force
    avm install latest
    avm use latest
  5. Node.js & Yarn: Use nvm to install Node.js (v18+).

    npm install -g yarn

Verification

Run the following command to verify your installation:

rustc --version && solana --version && anchor --version && surfpool --version && node --version && yarn --version

Successful Output:

Installed Versions:
Rust: rustc 1.91.1 (ed61e7d7e 2025-11-07)
Solana CLI: solana-cli 3.0.10 (src:96c3a851; feat:3604001754, client:Agave)
Anchor CLI: anchor-cli 0.32.1
Surfpool CLI: surfpool 0.12.0
Node.js: v24.10.0
Yarn: 1.22.1

Installation

  1. Clone the repository

    git clone https://github.com/raushan728/solana-subscription-system.git
    cd solana-subscription-system
  2. Install root dependencies

    yarn install
  3. Install frontend dependencies

    cd app
    npm install
    cd ..

Smart Contract Deployment

  1. Configure Solana CLI

    solana config set --url https://api.devnet.solana.com
  2. Build the Program

    anchor build
  3. Deploy to Devnet

    anchor deploy

    Note: Update the Program ID in lib.rs and Anchor.toml after the initial build.

Frontend Setup

  1. Synchronize IDL Copy the generated IDL file from target/idl/ to app/app/utils/idl.json.

  2. Update Configuration Update the PROGRAM_ID constant in app/app/hooks/useSubscription.ts with your deployed Program ID.

  3. Run Application

    cd app
    npm run dev

    The application will be available at http://localhost:3000.

CLI Usage

The project includes scripts to simulate the subscription lifecycle via the terminal.

Command Description
anchor run create-plan Initializes a new subscription plan on-chain.
anchor run subscribe Subscribes the configured wallet to the plan.
anchor run trigger-billing Attempts to withdraw funds (subject to time-lock).
anchor run cancel Cancels the active subscription immediately.

Project Structure

solana-subscription-system/
├── programs/
│   └── solana_subscription_system/
│       └── src/lib.rs            # Core Smart Contract Logic
├── app/                          # Next.js Frontend
│   ├── app/
│   │   ├── components/           # UI Components
│   │   ├── hooks/                # Web3 Logic
│   │   └── page.tsx              # Main Dashboard
├── scripts/                      # Automation & Testing Scripts
├── tests/                        # Integration Tests
└── Anchor.toml                   # Project Configuration

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contact

Raushan Kumar - LinkedIn

Email: [email protected]

About

A decentralized recurring payment protocol on Solana built with Anchor, Rust, and Next.js. Features trustless escrow vaults and time-locked billing

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published