By default, you don't need to configure an RPC URL. The agent uses the default x402 facilitator service at https://x402.org/facilitator, which handles all blockchain interactions for you:
Your Agent → x402 Facilitator → Blockchain (via Facilitator's RPC)
The facilitator service:
- Manages RPC connections
- Verifies payment signatures
- Executes blockchain transactions
- Handles gas management
- Returns transaction receipts
┌─────────────────┐
│ Your Agent │
│ (server.ts) │
└────────┬────────┘
│
│ Payment verification/settlement
▼
┌─────────────────┐
│ Facilitator │
│ (x402.org or │
│ custom) │
└────────┬────────┘
│
│ RPC calls
▼
┌─────────────────┐
│ Blockchain │
│ (Base, Polygon, │
│ etc.) │
└─────────────────┘
No configuration needed! Just leave .env as is:
# No FACILITATOR_URL needed
# Uses https://x402.org/facilitator by defaultThe default facilitator handles everything for you.
If you want to keep settlement inside this server (no facilitator call), enable the built-in direct flow:
SETTLEMENT_MODE=local
PRIVATE_KEY=your_private_key_here
# Optional - override default RPC endpoint for the selected network
RPC_URL=https://base-sepolia.g.alchemy.com/v2/YOUR_KEY
# Provide ASSET_ADDRESS/ASSET_NAME if using a non-built-in network
ASSET_ADDRESS=0xTokenAddress
ASSET_NAME=USDC
CHAIN_ID=84532With these variables set, the agent:
- Verifies the EIP-3009 payload locally
- Uses your RPC endpoint to call
transferWithAuthorizationon the USDC contract
Make sure the wallet behind PRIVATE_KEY holds the gas token for the selected network.
If you want to use a different facilitator service, set:
FACILITATOR_URL=https://your-custom-facilitator.com
FACILITATOR_API_KEY=your_api_key_if_required
# Provide ASSET_ADDRESS/ASSET_NAME if the facilitator expects a different asset for your network
ASSET_ADDRESS=0xTokenAddress
ASSET_NAME=USDC
CHAIN_ID=84532Your custom facilitator would need to implement the x402 facilitator API:
POST /verify- Verify payment signaturesPOST /settle- Settle payments on-chain
To run your own facilitator with custom RPC:
- Deploy your own facilitator service (see x402 facilitator repo)
- Configure the facilitator with your RPC URL:
# In your facilitator's config RPC_URL=https://base-sepolia.g.alchemy.com/v2/YOUR_KEY
- Point this agent to your facilitator (for example, if it runs locally at
http://localhost:4000):# In agent/.env FACILITATOR_URL=https://your-facilitator.yoursite.com
Local settlement mode already performs on-chain verification/settlement for USDC via EIP-3009. If you need more control (additional assets, alternative schemes), you can still implement your own executor:
- Replace or extend
src/MerchantExecutor.ts - Use
ethers(or another SDK) together with your RPC URL(s) - Add any custom verification/settlement logic your flow requires
Use the bundled executor as a reference for how to construct payment requirements, log settlement details, and surface errors back to the server.
If you need to configure an RPC URL (for custom facilitator or direct integration), here are popular providers:
RPC_URL=https://base-sepolia.g.alchemy.com/v2/YOUR_API_KEYSign up: https://www.alchemy.com
RPC_URL=https://base-sepolia.infura.io/v3/YOUR_PROJECT_IDSign up: https://www.infura.io
RPC_URL=https://your-endpoint.base-sepolia.quiknode.pro/YOUR_TOKEN/Sign up: https://www.quicknode.com
# Base Sepolia
RPC_URL=https://sepolia.base.org
# Base Mainnet
RPC_URL=https://mainnet.base.org- Alchemy:
https://base-sepolia.g.alchemy.com/v2/YOUR_KEY - Public:
https://sepolia.base.org - Chain ID: 84532
- Alchemy:
https://base-mainnet.g.alchemy.com/v2/YOUR_KEY - Public:
https://mainnet.base.org - Chain ID: 8453
- Alchemy:
https://polygon-amoy.g.alchemy.com/v2/YOUR_KEY - Chain ID: 80002
- Alchemy:
https://eth-sepolia.g.alchemy.com/v2/YOUR_KEY - Infura:
https://sepolia.infura.io/v3/YOUR_PROJECT_ID - Chain ID: 11155111
The agent currently uses:
File: src/server.ts
const merchantOptions = {
payToAddress: PAY_TO_ADDRESS,
network: resolvedNetwork,
price: 0.1,
facilitatorUrl: FACILITATOR_URL,
facilitatorApiKey: FACILITATOR_API_KEY,
};
const merchantExecutor = new MerchantExecutor(merchantOptions);
if (FACILITATOR_URL) {
console.log(`🌐 Using custom facilitator: ${FACILITATOR_URL}`);
} else {
console.log('🌐 Using default facilitator: https://x402.org/facilitator');
}✅ Use the default facilitator (https://x402.org/facilitator)
- No configuration needed
- Works out of the box
- Handles testnet transactions
Consider these options:
-
Default facilitator (easiest)
- Managed service
- No infrastructure to maintain
- May have rate limits
-
Custom facilitator (recommended)
- Your own RPC endpoints
- Better control and monitoring
- Can optimize for your needs
- Set up failover/redundancy
-
Direct integration (advanced)
- Maximum control
- Requires blockchain expertise
- More maintenance
- Check facilitator URL is accessible
- Verify API key if using custom facilitator
- Check RPC endpoint is responding (if self-hosting)
- If you're using the hosted facilitator, retry later or contact support if the status page reports issues
- If you're running a custom facilitator, ensure its RPC URL matches the selected network, the settlement wallet has gas, and the RPC endpoint is healthy
- Network mismatch (e.g., mainnet signature on testnet)
- Check NETWORK env variable matches RPC network
Quick Answer:
- RPC URL is not required for basic setup
- The default facilitator at
https://x402.org/facilitatorhandles blockchain interactions - Set
SETTLEMENT_MODE=local(withPRIVATE_KEY/RPC_URL) for on-chain settlement inside this server - Use
FACILITATOR_URLto point at a custom facilitator endpoint
Environment Variables:
# Required
OPENAI_API_KEY=your_key
PAY_TO_ADDRESS=0xYourAddress
# Optional - local (direct) settlement
SETTLEMENT_MODE=local
PRIVATE_KEY=your_private_key
RPC_URL=https://base-sepolia.g.alchemy.com/v2/YOUR_KEY
CHAIN_ID=84532
# Optional - custom facilitator endpoint
FACILITATOR_URL=https://your-facilitator.com
FACILITATOR_API_KEY=your_key
# Optional - asset overrides (required if NETWORK isn't base/base-sepolia/polygon/polygon-amoy)
ASSET_ADDRESS=0xTokenAddress
ASSET_NAME=USDC
EXPLORER_URL=https://explorer.your-network.org
# Optional - ensure payment requirements include a fully-qualified endpoint URL
SERVICE_URL=https://your-domain.com/process