Skip to content
eshaanmathakariPublic

About

x402 based AI agents tipping system based on Solana blockchain

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

62 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Auton - Solana x402 Pay-to-Access Drops

Auton started as a lightweight tipping miniapp and now ships a Patreon-style, pay-to-access experience on Solana Devnet using the x402 protocol. Creators encrypt any file (video, audio, PDF, zip, text) client-side, choose whether to surface a spoiler, and fans unlock the full drop via a one-time Solana payment. Funds stream straight to the creatorโ€™s walletโ€”no custody, no platform middlemen, and purchases are final on-chain.

๐Ÿš€ Features

  • Encrypted paywall drops: Upload any file, encrypt with AES-256-GCM, and store on S3 (or local dev storage) before sharing a pay-to-access link.
  • Preview control: Give fans nothing, a short teaser, or a custom preview file. Creators choose โ€œauto snippetโ€, โ€œcustom textโ€, or โ€œdemo uploadโ€.
  • Instant wallet payouts: Solana Pay flows send funds directly to each creator. Auton never holds custody and surfaces an explicit โ€œno refundsโ€ disclaimer.
  • x402-first server: /content/:id/paywall responds with HTTP 402 Payment Required, Solana Pay headers, and unique payment IDs + references.
  • Short-lived access tokens: After on-chain verification, users receive a JWT-style token and signed asset URL that expires within minutes.
  • Wallet Adapter UX: Phantom + Solflare via @solana/wallet-adapter power both creator onboarding and buyer checkout, including direct extension checks on desktop.
  • Legacy tipping mode: Original /tip/:creatorId endpoints still exist for simple gratuities or backwards compatibility.

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    encrypt/upload     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Next.js Frontend    โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถโ”‚ Express x402 API             โ”‚
โ”‚                     โ”‚                       โ”‚                              โ”‚
โ”‚ โ€ข Creator workspace โ”‚โ—€โ”€โ”€ gated asset token โ”€โ”ค โ€ข /content CRUD + previews   โ”‚
โ”‚ โ€ข Content paywall   โ”‚                       โ”‚ โ€ข 402 paywall + verification โ”‚
โ”‚ โ€ข Wallet Adapter UI โ”‚                       โ”‚ โ€ข AES key custody + JWT      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
          โ”‚                                                โ”‚
request txโ”‚                                                โ”‚verify tx
          โ–ผ                                                โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Solana wallets      โ”‚                          โ”‚  Storage (S3 or local)  โ”‚
โ”‚  (Phantom/Solflare)  โ”‚                          โ”‚  โ€ข Encrypted blobs      โ”‚
โ”‚  โ€ข Signs payments    โ”‚                          โ”‚  โ€ข Optional preview     โ”‚
โ”‚  โ€ข Receives access   โ”‚                          โ”‚                         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“‹ Prerequisites

  • Node.js 18+ and npm
  • A Solana wallet (Phantom, Solflare, etc.)
  • Solana CLI (optional, for wallet generation)

๐Ÿ› ๏ธ Installation

1. Clone the Repository

git clone <[repository-url](https://github.com/eshaanmathakari/auton)>
cd auton

2. Backend Setup

cd backend
npm install

Generate a platform wallet:

npm run generate-wallet

This will create a .env file with your platform wallet address. You'll need to fund this wallet with Devnet SOL:

Create/extend backend/.env with the new paywall parameters:

ACCESS_TOKEN_SECRET=replace-me
PUBLIC_API_BASE=http://localhost:3001
PAYMENT_TTL_MINUTES=10
ACCESS_TOKEN_TTL_SECONDS=300
PLATFORM_FEE_PERCENTAGE=0
# Optional S3 upload path
# S3_BUCKET=your-bucket
# S3_REGION=us-east-1
# AWS_ACCESS_KEY_ID=...
# AWS_SECRET_ACCESS_KEY=...

If S3 variables are omitted (or USE_LOCAL_STORAGE=true), the server writes encrypted blobs to backend/uploads/ (gitignored) so you can demo everything locally.

3. Frontend Setup

cd frontend
npm install

Create a .env.local file:

NEXT_PUBLIC_API_URL=http://localhost:3001

๐Ÿš€ Running Locally

Start Backend Server

cd backend
npm run dev

The backend will run on http://localhost:3001

Start Frontend

cd frontend
npm run dev

The frontend will run on http://localhost:3000

๐Ÿ“– Usage

For Creators

  1. Run both servers and visit http://localhost:3000.
  2. Connect Phantom/Solflare (or manually paste a payout address). A creator ID is derived from your wallet prefix.
  3. Fill out the new โ€œEncrypt & publishโ€ form:
    • Upload any file to gate.
    • Pick a preview strategy: auto text snippet, custom teaser text, teaser file, or fully gated.
    • Set price (SOL for MVP), categories, and whether to allow downloads after unlock.
  4. Submit. The backend encrypts the payload, stores it, and returns a sharable link: /content/<contentId>.
  5. Manage all drops from the dashboardโ€”preview snippet, price badge, stream/download toggle.

For Buyers

  1. Open a creatorโ€™s share link (/content/<contentId>).
  2. Review the spoiler/preview and the mandatory โ€œno refundsโ€ disclaimer.
  3. Connect a wallet, click โ€œGet payment requestโ€ to receive the HTTP 402 payload, then approve the SOL transfer.
  4. After on-chain confirmation, the app returns a short-lived download URL (backed by an HMAC access token). Click โ€œOpen downloadโ€ to decrypt and fetch the file.

Legacy Tipping

The original /tip/:creatorId and dashboard remain available in case you still want lightweight tipping links beside the premium paywall.

๐Ÿ”Œ API Endpoints

Pay-to-Access Endpoints

Method & Path Description
POST /content Accepts encrypted upload metadata (base64 payload), preview preferences, price, categories, etc. Stores AES-256-GCM ciphertext + preview artifacts.
GET /content Lists every published drop (optionally filtered by ?creatorId=).
GET /content/:id Returns metadata + preview details without exposing encryption keys.
GET /content/:id/paywall?buyerPubkey=... Responds with HTTP 402, Solana Pay headers, and a short-lived payment intent tied to the buyer.
POST /content/:id/paywall Accepts { paymentId, signature, buyerPubkey }, verifies the on-chain transfer, records an access grant, and returns { accessToken, downloadUrl }.
GET /content/:id/asset?token=... Validates the signed token, decrypts the ciphertext, and streams the original file (respecting download/stream settings).
GET /content/:id/preview-asset If a creator uploaded a custom teaser file, this endpoint streams it in the clear.

All paywall responses include the non-refundable disclaimer so wallets and frontends can surface it before payment.

Legacy Tipping Endpoints

The previous tipping API is untouched and still works side-by-side with the new paywall:

GET /tip/:creatorId

Returns a 402 Payment Required response with payment parameters.

Query Parameters:

  • amount (optional): Amount in SOL/USDC (default: 0.1)
  • assetType (optional): 'SOL' or 'USDC' (default: 'SOL')
  • walletAddress (optional): Creator wallet address (if creator not registered)

Response Headers (402):

  • X-Payment-Required: 'true'
  • X-Payment-Id: Unique payment ID
  • X-Max-Amount: Maximum amount required
  • X-Asset-Type: Asset type (SOL/USDC)
  • X-Payment-Address: Recipient wallet address
  • X-Platform-Fee: Platform fee amount
  • X-Creator-Amount: Amount creator will receive
  • X-Network: Network (devnet)
  • X-Nonce: Payment nonce

POST /tip/:creatorId

Submit payment transaction for verification.

Request Body:

{
  "signature": "transaction_signature",
  "paymentId": "payment_id_from_402_response",
  "fromAddress": "tipper_wallet_address"
}

Response:

{
  "success": true,
  "message": "Payment verified and tip recorded",
  "tip": {
    "id": "tip_id",
    "amount": "0.1",
    "assetType": "SOL",
    "signature": "transaction_signature",
    "timestamp": "2024-01-01T00:00:00.000Z"
  },
  "transactionUrl": "https://explorer.solana.com/tx/..."
}

GET /tips/:creatorId

Get tip history for a creator.

Response:

{
  "creatorId": "creator_id",
  "creator": {
    "id": "creator_id",
    "walletAddress": "wallet_address",
    "createdAt": "2024-01-01T00:00:00.000Z"
  },
  "tips": [...],
  "totals": {
    "totalSOL": 1.5,
    "totalCreatorAmountSOL": 1.44
  },
  "count": 10
}

๐ŸŽจ Embeddable Widget

Creators can embed a tip button on their websites:

<a href="https://your-domain.com/tip/YOUR_CREATOR_ID" 
   target="_blank" 
   rel="noopener noreferrer"
   style="display: inline-flex; align-items: center; gap: 8px; padding: 12px 24px; background: linear-gradient(135deg, #9333ea 0%, #6366f1 100%); color: white; border: none; border-radius: 8px; font-size: 16px; font-weight: 600; cursor: pointer; text-decoration: none;">
  ๐Ÿ’œ Tip with Auton
</a>

See frontend/public/widget-example.html for more examples.

๐Ÿ”’ Security Considerations

  • All transactions are verified on-chain before being recorded
  • Payment signatures are validated against Solana blockchain
  • Platform wallet private keys should never be committed to version control
  • Use environment variables for sensitive configuration

๐Ÿงช Testing

Pay-to-Access Flow

  1. Start backend (npm run dev in /backend) and frontend (npm run dev in /frontend).
  2. Connect Wallet A on the homepage, upload a small text file, and publish it (preview auto or custom).
  3. Copy the generated link /content/<id> and open it in an incognito window with Wallet B.
  4. Request the payment instructions, inspect the HTTP 402 headers in DevTools if needed.
  5. Approve the SOL transfer, wait for confirmation, and click โ€œOpen downloadโ€ to verify the decrypted file contents.
  6. Check the backend logs (or backend/db.json) to confirm the payment intent + access grant records.

Legacy Tipping Flow

  1. Connect a creator wallet and grab the /tip/<creatorId> link.
  2. Open it with a second wallet, choose an amount, and submit the transaction.
  3. Confirm the tip shows up in the historical list as before.

๐Ÿ“ฆ Deployment

Backend Deployment (Vercel)

  1. Create a vercel.json in the backend directory:
{
  "version": 2,
  "builds": [
    {
      "src": "server.js",
      "use": "@vercel/node"
    }
  ],
  "routes": [
    {
      "src": "/(.*)",
      "dest": "server.js"
    }
  ]
}
  1. Set environment variables in Vercel dashboard
  2. Deploy: vercel --prod

Frontend Deployment (Vercel)

  1. Update NEXT_PUBLIC_API_URL in .env.local to your backend URL
  2. Deploy: vercel --prod

๐Ÿ—‚๏ธ Project Structure

auton/
โ”œโ”€โ”€ backend/
โ”‚   โ”œโ”€โ”€ routes/
โ”‚   โ”‚   โ”œโ”€โ”€ tip.js             # Legacy tipping endpoint
โ”‚   โ”‚   โ”œโ”€โ”€ tips.js            # Tip history endpoint
โ”‚   โ”‚   โ””โ”€โ”€ content.js         # Encrypted content + paywall routes
โ”‚   โ”œโ”€โ”€ utils/
โ”‚   โ”‚   โ”œโ”€โ”€ accessToken.js    # Short-lived download tokens
โ”‚   โ”‚   โ”œโ”€โ”€ encryption.js     # AES helpers
โ”‚   โ”‚   โ””โ”€โ”€ payment.js        # Payment verification logic
โ”‚   โ”œโ”€โ”€ storage/
โ”‚   โ”‚   โ”œโ”€โ”€ localStorage.js   # Dev-friendly filesystem storage
โ”‚   โ”‚   โ”œโ”€โ”€ s3Storage.js      # Optional AWS S3 adapter
โ”‚   โ”‚   โ””โ”€โ”€ storageProvider.js
โ”‚   โ”œโ”€โ”€ scripts/
โ”‚   โ”‚   โ””โ”€โ”€ generate-wallet.js  # Wallet generation script
โ”‚   โ”œโ”€โ”€ database.js          # Simple JSON database
โ”‚   โ”œโ”€โ”€ db.json              # Database file
โ”‚   โ””โ”€โ”€ server.js            # Express server
โ”œโ”€โ”€ frontend/
โ”‚   โ”œโ”€โ”€ app/
โ”‚   โ”‚   โ”œโ”€โ”€ page.tsx         # Creator workspace (upload + catalog)
โ”‚   โ”‚   โ”œโ”€โ”€ content/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ [contentId]/ # Paywall + unlock flow
โ”‚   โ”‚   โ””โ”€โ”€ tip/
โ”‚   โ”‚       โ””โ”€โ”€ [creatorId]/ # Legacy tipping page
โ”‚   โ”‚   โ””โ”€โ”€ layout.tsx       # Root layout with wallet provider
โ”‚   โ”œโ”€โ”€ components/
โ”‚   โ”‚   โ””โ”€โ”€ WalletContextProvider.tsx
โ”‚   โ””โ”€โ”€ public/
โ”‚       โ””โ”€โ”€ widget-example.html
โ””โ”€โ”€ README.md

๐Ÿค Contributing

This project was built for the Solana X402 Hackathon. Contributions are welcome!

๐Ÿ“„ License

MIT License

๐Ÿ™ Acknowledgments

  • Solana Foundation for the x402 protocol
  • Solana Wallet Adapter team
  • OpenLibx402-Core contributors

๐Ÿ“š Resources

๐Ÿ”ฎ Future Enhancements

  • USDC token transfer support
  • Multi-chain support
  • Social login integration
  • Automated wallet creation for new users
  • Analytics dashboard
  • Recurring tips/subscriptions
  • NFT gating for premium content

About

x402 based AI agents tipping system based on Solana blockchain

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages