Skip to content

traderfoxexe/BagsPay

Repository files navigation

BagsPay - x402 Payment Infrastructure for Solana

The Stripe of Bags. Subscription and payment rails where any app or AI agent can charge payments on Solana with automatic Bags fee sharing built in.

Every payment generates fees for $BAGS holders. Every SaaS product, agent service, or creator paywall that plugs in grows the ecosystem.

How It Works

BagsPay implements the x402 protocol for Solana:

Agent/User ──> Service (BagsPay middleware)
                 │
                 ├── No payment? Return HTTP 402 + payment requirements
                 │
                 └── Has X-PAYMENT header? ──> Facilitator verifies + settles
                                                  │
                                                  ├── 97% to merchant
                                                  ├── 2% to $BAGS vault
                                                  └── 1% to protocol treasury

Quick Start

For merchants (accept payments in 10 lines)

import { Hono } from "hono";
import { bagspay } from "@bagspay/server";

const app = new Hono();

app.use("/api/premium/*", bagspay({
  price: { amount: "0.01", asset: "USDC" },
  payTo: "YOUR_WALLET",
  facilitatorUrl: "http://localhost:3100",
}));

app.get("/api/premium/data", (c) => c.json({ data: "premium content" }));

For agents (pay for services automatically)

import { BagsPayClient, keypairAdapter } from "@bagspay/client";
import { Keypair } from "@solana/web3.js";

const client = new BagsPayClient({
  wallet: keypairAdapter(Keypair.generate()),
});

// Automatically handles 402 -> sign -> pay -> retry
const res = await client.fetch("https://api.example.com/premium/data");
const data = await res.json();

Architecture

packages/
  core/       - x402 types, constants, utilities
  server/     - Hono middleware for merchants
  client/     - Auto-pay fetch wrapper for agents

apps/
  facilitator/       - Payment verification + Solana settlement
  demo-api/          - Example paid API
  agent-marketplace/ - AI agent service marketplace (first merchant)

Development

# Install dependencies
bun install

# Start the facilitator
bun run --watch apps/facilitator/src/index.ts

# Start the demo API (separate terminal)
bun run --watch apps/demo-api/src/index.ts

# Start the agent marketplace (separate terminal)
bun run --watch apps/agent-marketplace/src/index.ts

# Type check everything
bun run typecheck

Agent Marketplace

The marketplace comes with 3 seed agents:

Agent Price Description
Price Analysis 0.005 USDC/call Token price action from DexScreener
Wallet Scanner 0.01 USDC/call Wallet holdings and SOL balance
Token Research 0.01 USDC/call Token supply, market data, risk info

Register your agent

curl -X POST http://localhost:3300/agents/register \
  -H "Content-Type: application/json" \
  -d '{
    "id": "my-agent",
    "name": "My Agent",
    "description": "Does something useful",
    "pricePerCall": "0.01",
    "endpoint": "https://my-agent.example.com/api"
  }'

Fee Structure

Every BagsPay transaction splits fees automatically via Bags Fee Share V2:

  • 97% to the merchant
  • 2% to the $BAGS fee share vault (distributed to top holders)
  • 1% to BagsPay protocol treasury

Configurable per-merchant in basis points (10000 = 100%).

Hackathon Tracks

  • Bags API - Token launch, fee share configuration
  • Fee Sharing - Every payment routes fees to $BAGS holders
  • Payments - x402 protocol implementation for Solana
  • AI Agents - Agent marketplace + auto-pay client SDK

Tech Stack

  • Bun + TypeScript
  • Hono (server framework)
  • @solana/web3.js + @solana/spl-token
  • SQLite (subscriptions + nonce replay protection)
  • Turborepo (monorepo)

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors