Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Crossmint/crossmint-agentic-finance/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The Send Tweet Agent is a unified Next.js application that posts tweets to X/Twitter for payment via the x402 protocol. The app uses Next.js middleware for payment validation, API routes for tweet posting, and a React frontend with Crossmint smart wallets for payment authorization.Architecture
This is a full-stack Next.js application with:- Frontend: React app with Crossmint wallet integration (
/) - Middleware: x402 payment validation using
x402-next - API Routes:
/api/tweet- Posts tweets (protected by x402 payment)/api/health- Health check endpoint/api/wallet/init- Creates wallets for users
- Twitter Integration: Server-side Twitter API v2 integration
Prerequisites
- Node.js 18.0.0+
- Twitter Developer Account with API v2 access (Elevated tier, Read+Write permissions)
- Crossmint API key (
sk_staging_*orsk_production_*) - Base Sepolia testnet (default) or Base mainnet
User Requirements
Users only need:- An email address to create an account
- USDC in their wallet to send tweets ($1 per tweet)
Installation
Configuration
Create.env.local in the sendvia directory:
Required Variables
Twitter API Setup
- Create app at https://developer.x.com/en/portal/dashboard
- Set app permissions to “Read and Write” (not “Read only”)
- Apply for “Elevated” access (required for v2 API tweet posting)
- Generate API keys after setting permissions
- Verify Twitter account has phone number attached
- Copy all 4 credentials to
sendvia/.env.local
Running the Application
Development Mode
Production Build
Usage
- Open http://localhost:3000
- Enter your email address to create an account
- Click “Create Account” - creates a secure payment wallet automatically
- Enter your tweet text (max 280 characters)
- Optional: Add an image URL
- Click “Send Tweet · $1”
- Payment is processed automatically and tweet is posted
- View your tweet on Twitter or check the payment transaction on-chain
API Reference
POST /api/wallet/init
Creates a new wallet for a user (requires backend Crossmint API key). Request:400- Invalid or missing email500- Server configuration error or wallet creation failed
GET /api/health
Health check endpoint. Response (200):POST /api/tweet
Posts tweet with payment verification (protected by x402 middleware). Authentication: x402 payment protocol (EIP-712 signature) Price: $1 USDC (configurable viaPRICE_USDC)
Headers:
400- Missing or invalid tweet text / Tweet exceeds 280 characters401- Twitter API authentication failed402- Payment required or verification failed403- Twitter API permission denied429- Twitter API rate limit exceeded500- Internal server error or Twitter API error
Payment Flow
Technical Architecture
Next.js Middleware (sendvia/middleware.ts)
- x402-next payment middleware for Next.js
- Validates EIP-712 signatures before allowing API access
- Configured for
/api/tweetendpoint - External facilitator handles on-chain settlement (https://x402.org/facilitator)
API Routes (sendvia/app/api/)
/api/wallet/init- Creates wallet using backend Crossmint API key/api/tweet- Twitter API v2 integration, posts tweets after payment verification/api/health- Health check and configuration status- Server-side Twitter client with image download/upload support
Frontend (sendvia/app/page.tsx)
- Minimal, tweet-first user interface
- Email-only account creation (no API key required from users)
- x402-axios interceptor for automatic payment handling
- localStorage persistence for account data
- Developer mode toggle for technical logs
- User-friendly error messages and status updates
- Responsive design with success animations
x402 Adapter (sendvia/app/x402Adapter.ts)
- Converts Crossmint wallet to x402-compatible signer
- Handles ERC-6492 signatures (pre-deployed wallets)
- Handles EIP-1271 signatures (deployed wallets)
- Normalizes signature formats for verification
File Structure
Troubleshooting
Error: MERCHANT_ADDRESS is required
Error: Twitter API 403 Permission Denied
- Verify app has “Read and Write” permissions
- Regenerate access tokens after changing permissions
- Confirm account has “Elevated” access (not Basic)
- Ensure Twitter account has verified phone number
Error: Twitter API 401 Authentication Failed
- Verify all 4 credentials in
sendvia/.env.localare correct - Check for extra spaces, quotes, or newlines in values
- Regenerate tokens if credentials are old
Error: Payment verification failed
- Check
X402_NETWORKmatches between client and server (default: base-sepolia) - Verify
MERCHANT_ADDRESSis valid Ethereum address - Confirm Crossmint wallet initialized successfully
- Check browser console for x402 signer errors
Error: Signature timeout with deployed wallets
Networks
Base Sepolia (Default Testnet)
- Network ID: 84532
- RPC: https://sepolia.base.org
- Block explorer: https://sepolia.basescan.org
- Get testnet USDC: Circle Faucet
Base Mainnet
- Network ID: 8453
- RPC: https://mainnet.base.org
- Block explorer: https://basescan.org
- Set
X402_NETWORK=basein.env.local
Production Deployment
-
Set production environment variables:
X402_NETWORK=base- Use production Crossmint API key (
sk_production_*) - Set production
MERCHANT_ADDRESS
- Build and deploy:
- Configure reverse proxy (nginx/caddy) for HTTPS
- Monitor logs for errors
- Test with small amounts before production use
Dependencies
- next@^15.5.3 - Full-stack framework
- react@^19.1.1 - Frontend
- x402-next@^0.6.0 - Next.js payment middleware
- x402-axios@^0.6.6 - Client-side payment interceptor
- twitter-api-v2@^1.27.0 - Twitter API client
- @crossmint/wallets-sdk@0.14.0 - Smart wallet integration
- viem@^2.38.0 - Ethereum utilities