x402-gasless
v1.0.0-beta.1
Published
Gasless x402 facilitator using Alchemy Account Abstraction - Enable gasless USDC payments for your x402 resource servers
Maintainers
Readme
x402-gasless
Gasless transactions for x402 payments using Alchemy's Account Abstraction
Enable your users to pay with USDC without worrying about gas fees. Fork this repo, add your Alchemy API key, and deploy in 5 minutes.
⚠️ Beta Software - Core functionality is tested and working with real Alchemy Account Abstraction integration. The demo client demonstrates actual gasless transactions. Test thoroughly in your environment before production use. Report issues →
Features
- Gasless for users - No ETH needed, just USDC
- Pay Alchemy directly - No middleman, no markup
- Fork & deploy in 5 min - Batteries included
- Multi-chain support - Base, Ethereum, Polygon, Arbitrum, Optimism
- Plug-and-play - Works with Vend and any x402 resource server
- Free tier available - Alchemy offers free gas sponsorship tier
Quick Start
Option 1: Install from npm (Recommended)
# Install globally
npm install -g x402-gasless
# Or use npx (no installation needed)
npx x402-gasless setup
npx x402-gasless startOption 2: Clone from GitHub
# 1. Clone the repo
git clone https://github.com/usmaneth/x402-gasless
cd x402-gasless
# 2. Install dependencies
npm install
# 3. Setup (interactive wizard)
npm run setup
# Prompts for Alchemy API key and creates Gas Manager policy
# 4. Start the facilitator
npm run dev
# Server running at http://localhost:3000 ✅Costs & Economics
Understanding "Gasless":
Gasless ≠ Free — Here's what it means:
- ✅ Gas fees: $0 (Alchemy sponsors transaction gas)
- ❌ USDC payment: Required (users pay for the resource/API access)
Think of it like Amazon Prime:
- Shipping is free (gas) = No ETH needed
- Product costs money (USDC) = Payment for the resource
Example Transaction:
User wants blockchain data from Vend (costs 0.01 USDC)
Traditional:
- 0.01 USDC for data ✓
- ~$0.02 ETH for gas ✗ (user needs ETH!)
With x402-gasless:
- 0.01 USDC for data ✓
- $0.00 ETH for gas ✓ (Alchemy sponsors it!)Your Costs (Platform Operator):
- Gas sponsorship: ~$0.01/transaction (you pay Alchemy)
- Free tier: Alchemy offers gas sponsorship credits
- No markup: Direct Alchemy pricing
- Users pay you: USDC for resources (you set the price)
📖 How It Works
Client (Smart Wallet) → Resource Server (Vend) → x402-gasless Facilitator → Alchemy Gas Manager → Blockchain- Client creates a UserOperation (signed USDC transfer) using Alchemy smart wallet
- Resource Server (like Vend) forwards the UserOp to x402-gasless for verification
- x402-gasless verifies the signature and adds Alchemy Gas Manager paymaster data
- Alchemy sponsors the gas and submits the transaction
- User pays 0 gas - only the USDC for the resource
Try the Demo Client
Test the complete gasless flow with our ready-to-run demo:
cd examples/demo-client
npm install
cp .env.example .env
# Edit .env with your Alchemy API key and private key
npm startThe demo shows:
- Creating Alchemy smart wallet
- Building UserOperations for USDC transfers
- Verifying payments with facilitator
- Settling with gas sponsorship
- Monitoring gasless transactions
🎯 API Endpoints
POST /verify
Verify a UserOperation signature and payment details.
curl -X POST http://localhost:3000/verify \
-H "Content-Type: application/json" \
-d '{
"x402Version": 1,
"paymentHeader": "base64-encoded-userop",
"paymentRequirements": {
"scheme": "aa-erc4337",
"network": "base-sepolia",
"maxAmountRequired": "10000",
"payTo": "0x...",
"asset": "0x..."
}
}'POST /settle
Settle a verified payment by submitting to blockchain with gas sponsorship.
GET /supported
Get list of supported payment schemes and networks.
GET /health
Health check endpoint.
🌐 Supported Networks
Auto-configured out of the box:
- Base Sepolia (testnet)
- Base Mainnet
- Ethereum Sepolia (testnet)
- Ethereum Mainnet
- Polygon Mainnet
- Arbitrum Mainnet
- Optimism Mainnet
All USDC contracts pre-configured!
Project Structure
x402-gasless/
├── src/
│ ├── index.js # Express app entry point
│ ├── config.js # Smart configuration
│ ├── logger.js # Logging setup
│ ├── routes/ # API endpoints
│ ├── services/ # Core business logic
│ ├── middleware/ # Express middleware
│ └── utils/ # Utilities
├── scripts/
│ ├── setup.js # Interactive setup
│ ├── create-policy.js # Create Alchemy Gas Manager policy
│ └── test-connection.js # Test Alchemy connection
├── docs/ # Documentation
├── examples/ # Integration examples
└── tests/ # Test suiteDevelopment
# Run in development mode (auto-reload)
npm run dev
# Run tests
npm test
# Run tests in watch mode
npm run test:watch
# Test Alchemy connection
npm run test-connection
# Create Gas Manager policy
npm run create-policyDeployment
Railway (Recommended)
npm run deploy:railwayDocker
docker build -t x402-gasless .
docker run -p 3000:3000 --env-file .env x402-gaslessEnvironment Variables for Production
Make sure to set these in your deployment platform:
ALCHEMY_API_KEYALCHEMY_GAS_POLICY_IDNODE_ENV=productionPORT=3000(or your preferred port)
Documentation
Use Cases
- Data APIs: Sell blockchain data with USDC payments (like Vend)
- AI Agents: Enable autonomous payments without gas complexity
- Gaming: In-game purchases without users holding ETH
- DeFi: Onboard users without requiring gas tokens
- Paywalls: Monetize content with microtransactions
Contributing
Contributions welcome! Please read our Contributing Guide first.
License
MIT - Fork freely!
Links
Built with ❤️ for the x402 community
