Open-source infrastructure enabling autonomous AI agents to participate in the referral economy on Solana
Built with x402 payment protocol + Solana blockchain + Agent Economy integration
x402 Referral is a permissionless referral platform that combines:
- Solana blockchain for transparent campaign registry and proof logging
- x402 protocol for instant cryptocurrency payouts (HTTP 402)
- Agent Economy support for autonomous AI agents to earn and transact
✅ On-chain transparency - All campaigns and conversion proofs stored on Solana
✅ Instant payouts - Automated USDC payments via x402 protocol (< 3s latency)
✅ Fraud prevention - Built-in detection with IP/fingerprint/velocity checks
✅ Agent-native - AI agents can discover campaigns, generate links, and earn autonomously
✅ Permissionless - No approval needed, just connect wallet and start
┌─────────────────┐
│ Business │ Creates campaign
└────────┬────────┘
│
▼
┌─────────────────────────────────────────┐
│ Campaign Registry (Solana Program) │ ◄── On-chain
│ - Campaign metadata │
│ - Proof event logs (immutable) │
└─────────────────────────────────────────┘
│
▼
┌─────────────────┐ ┌──────────────────┐
│ Affiliate │────────►│ Referral Link │
└─────────────────┘ └──────────────────┘
│
▼
┌──────────────────┐
│ User Converts │
└────────┬─────────┘
│
▼
┌──────────────────────┐
│ Webhook → Verifier │
│ - Fraud checks │
│ - Submit proof │
└────────┬─────────────┘
│
▼
┌──────────────────────┐
│ Payout Service │
│ - Query /invoice │
│ - Pay via x402 │
│ - USDC on Solana │
└──────────────────────┘
| Component | Technology |
|---|---|
| Blockchain | Solana (Anchor 0.31.1) |
| Smart Contracts | Rust + Anchor Framework |
| Frontend | Next.js 16 (App Router) |
| Payments | x402 protocol + Coinbase CDP |
| Wallets | Phantom, Solflare, Backpack |
| Database | PostgreSQL (optional: Vercel Postgres) |
| Styling | Tailwind CSS 4 |
| State | TanStack Query + Zustand |
| Validation | Zod |
x402-referral/
├── anchor/ # Solana program
│ ├── programs/
│ │ └── referral_registry/ # Campaign registry + proof logging
│ └── tests/ # Anchor tests
├── app/ # Next.js frontend + API
│ ├── app/
│ │ ├── api/ # API routes
│ │ │ ├── webhooks/ # Conversion webhooks
│ │ │ ├── campaigns/ # Campaign CRUD
│ │ │ ├── payouts/ # Payout processing
│ │ │ └── x402/ # x402 endpoints
│ │ ├── business/ # Business dashboard
│ │ ├── affiliate/ # Affiliate dashboard
│ │ ├── r/[campaign]/[affiliate]/ # Referral handler
│ │ └── demo/ # Demo shop
│ ├── components/ # React components
│ ├── lib/
│ │ ├── solana/ # Anchor client
│ │ ├── db/ # Database schema
│ │ └── fraud/ # Fraud detection
│ └── providers/ # Wallet providers
├── packages/ # Shared SDKs (optional)
└── SPECS.md # Detailed specifications
- Node.js 18+
- pnpm 9+
- Rust 1.70+
- Solana CLI 2.x (via Anza)
- Anchor CLI (latest via AVM)
# Install Solana 2.x via Anza
sh -c "$(curl -sSfL https://release.anza.xyz/stable/install)"
# Verify installation
solana --version# Install Anchor Version Manager
cargo install --git https://github.com/coral-xyz/anchor avm --force
# Verify AVM installation
avm --version
# Install latest Anchor CLI
avm install latest
avm use latest
# Or install specific version
# avm install 0.32.1
# avm use 0.32.1
# Verify Anchor installation
anchor --versiongit clone https://github.com/maikershq/x402-referral.git
cd x402-referral
# Install Next.js dependencies
cd app && pnpm install
# Install Anchor dependencies
cd ../anchor && yarn install# Copy environment template
cp .env.example .env.local
# Configure your variables (see .env.example for details)
# Required:
# - NEXT_PUBLIC_CDP_CLIENT_KEY (from Coinbase Developer Portal)
# - DATABASE_URL (PostgreSQL connection string)cd anchor
anchor build
anchor deploy --provider.cluster devnet
# Copy the program ID and update .env.localcd ../app
pnpm devVisit http://localhost:3000
- Connect Wallet - Use Phantom/Solflare
- Create Campaign - Set payout amount, max conversions, duration
- Get Webhook URL - Configure in your app to track conversions
- Monitor Dashboard - Real-time analytics, fraud alerts, payouts
- Connect Wallet - Connects your identity
- Browse Campaigns - See available campaigns on-chain
- Generate Link - Creates signed referral URL
- Share & Earn - Get paid instantly via x402 when users convert
// Pseudo-code: Agent discovers and joins campaign
const campaigns = await querySolanaRegistry();
const bestCampaign = agent.selectByCriteria(campaigns);
const referralLink = await generateLink(bestCampaign.id, agent.pubkey);
// Agent promotes link in interactions
// When conversion happens, agent receives USDC via x402 /invoice endpoint# Anchor tests
cd anchor
anchor test
# Frontend tests (if implemented)
cd app
pnpm test# Build Anchor program
cd anchor
anchor build
# Build Next.js app
cd ../app
pnpm build- Update
Anchor.tomlto use mainnet - Get mainnet RPC endpoint (Helius/QuickNode recommended)
- Deploy program:
anchor deploy --provider.cluster mainnet-beta - Update frontend env vars with mainnet config
- Deploy frontend to Vercel:
vercel deploy --prod
See .env.example for all configuration options.
Key variables:
NEXT_PUBLIC_SOLANA_NETWORK- devnet or mainnet-betaNEXT_PUBLIC_PROGRAM_ID- Your deployed Anchor program IDNEXT_PUBLIC_CDP_CLIENT_KEY- Coinbase CDP API keyDATABASE_URL- PostgreSQL connection string
Built-in fraud detection includes:
- Device fingerprinting
- IP/ASN risk scoring
- Velocity limits (conversions per time window)
- Geo-anomaly detection
- Multi-touch attribution
Configure thresholds in lib/fraud/detector.ts
- elizaOS
- LangChain
- AutoGPT
- Agent Protocol
- Customer service agents earning commissions
- Content creation agents monetizing recommendations
- Analysis agents getting paid for insights
- Specialized assistants referring to platforms
POST /api/webhooks/conversion
{
"campaign_id": "string",
"affiliate_id": "string",
"conversion_type": "signup|purchase",
"metadata": { "fingerprint": "string" }
}GET /api/campaigns - List all campaigns
POST /api/campaigns - Create new campaign (requires wallet signature)
GET /api/x402/invoice?amount=5&conversion_id=123
Returns HTTP 402 with payment request details
Contributions welcome! Please open an issue or PR.
- Fork the repo
- Create feature branch (
git checkout -b feature/amazing) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing) - Open Pull Request
- Smart contracts audited: ❌ (TODO)
- Bug bounty program: ❌ (TODO)
- Report vulnerabilities: security@maikers.com
MIT License - see LICENSE file
- SPECS.md - Detailed technical specifications
- x402 Protocol - Payment protocol docs
- Solana Docs - Solana blockchain
- Anchor Book - Anchor framework
# 1. Start dev server
cd app && pnpm dev
# 2. Open browser to http://localhost:3000
# 3. Try the flow:
# - Go to /business/dashboard → Connect wallet → Create campaign
# - Go to /affiliate/dashboard → Connect wallet → Generate referral link
# - Click referral link → Complete signup on demo shop
# - See conversion tracked with fraud check and proof generation!- Business creates campaign on-chain (Solana transaction)
- Affiliate generates referral link (unique per affiliate)
- User clicks link → tracked via session → signs up on demo shop
- System validates (fraud check) → generates proof → processes payout
- Result: Affiliate earns USDC in <3 seconds ⚡
See DEMO.md for complete demo guide and video script.
🎥 Demo video coming soon (see DEMO.md for recording script)
- GitHub Issues: Create an issue
- Discord: Join community
- Email: support@maikers.com
Built for the Solana Agent Economy Hackathon
Enabling autonomous agents to transact and earn on-chain 🚀