Overview
Retrieves x402 payment technology documentation and code examples for gasless payments on Cronos.
Tool Name: get_x402_examples
What is x402?
x402 is a payment protocol for Cronos that enables:
Gasless Payments Users pay with stablecoins without holding CRO for gas
No Infrastructure Sellers verify/settle payments without running blockchain nodes
HTTP API Simple REST API integration (no blockchain expertise needed)
EIP-3009 Based Uses cryptographic signatures for authorization
Parameters
Action to perform Options: "search", "list", "get-overview", "list-all"
Search query (required for "search" action)
Filter by category Options: "client", "server", "middleware", "integration", "reference"
Filter by programming language Options: "typescript", "python", "javascript"
Response
{
"found" : true ,
"action" : "search" ,
"examples" : [
{
"title" : "Generate EIP-3009 Payment Header" ,
"description" : "Create a Base64-encoded signed payment header using EIP-3009" ,
"category" : "client" ,
"language" : "typescript" ,
"use_case" : "Generate gasless payment authorization from user wallet" ,
"code" : "import { Facilitator } from '@crypto.com/facilitator-client'; \n ..." ,
"dependencies" : [ "@crypto.com/facilitator-client" , "ethers" ],
"notes" : [
"Signer must have funds to authorize (but NOT to pay gas)" ,
"Facilitator pays gas fees on behalf of user"
],
"github_source" : "https://github.com/cronos-labs/x402-examples"
}
],
"total_count" : 1
}
Available Examples
Client (4 examples)
Server (3 examples)
Middleware (1 example)
Integration (2 examples)
Reference (2 examples)
Facilitator Client Setup
Initialize the facilitator client
Configure network settings
Generate Payment Requirements
Request payment details from facilitator
Get supported networks and tokens
Generate EIP-3009 Payment Header
Create signed payment authorization
Format as HTTP header
Client-Side Payment Flow (React)
Complete frontend implementation
User wallet integration
Verify Payment Request
Validate payment header
Check signature validity
Settle Payment On-Chain
Execute blockchain settlement
Handle confirmations
Payment Settlement Endpoint
Complete API endpoint
Error handling
Express Middleware for x402 Paywall
Automatic payment verification
Integrate into existing APIs
Full End-to-End Payment Flow
Complete implementation
Client + server integration
Python A2A Agent Payment Handler
AI agent payment processing
Autonomous transactions
Discover Supported Networks
Query available chains
Get token information
Environment Configuration
Setup and configuration
Best practices
Example Usage
Get Overview
result = use_mcp_tool(
server_name = "cato" ,
tool_name = "get_x402_examples" ,
arguments = {
"action" : "get-overview"
}
)
Search Examples
result = use_mcp_tool(
server_name = "cato" ,
tool_name = "get_x402_examples" ,
arguments = {
"action" : "search" ,
"query" : "payment header"
}
)
List by Category
result = use_mcp_tool(
server_name = "cato" ,
tool_name = "get_x402_examples" ,
arguments = {
"action" : "list" ,
"category" : "client" ,
"language" : "typescript"
}
)
List All Examples
result = use_mcp_tool(
server_name = "cato" ,
tool_name = "get_x402_examples" ,
arguments = {
"action" : "list-all"
}
)
Key Features
Zero Infrastructure No blockchain infrastructure required
Gasless Payments Facilitator pays gas on behalf of users
Stateless API No database needed for payment processing
EIP-3009 Signatures Cryptographic payment verification
Replay Protection Automatic protection against replay attacks
Production Ready Battle-tested reliability
Low Fees Extremely low transaction costs on Cronos
Micropayments Suitable for small payment amounts
Use Cases
E-commerce
API Paywalls
Micropayments
AI Agents (A2A)
SaaS Billing
Content
Accept cryptocurrency payments
No blockchain infrastructure
Simple REST API integration
Automatic settlement
Low payment processing fees
Perfect for online stores accepting crypto Charge for API access
HTTP 402 status codes
Pay-per-request model
Automatic verification
Easy middleware integration
Monetize APIs with crypto payments Enable small payments
Minimal transaction fees
Suitable for cents/micro-transactions
No minimum amounts
Fast settlement
Perfect for content, data, or resource sales Autonomous agent payments
Agents pay for resources
No human intervention
Programmatic payments
Machine-to-machine commerce
Enable autonomous AI agent economies Decentralized subscriptions
Crypto-based billing
Automatic renewals
No card processors
Global accessibility
Accept payments from anywhere Monetize digital content
Pay-per-view
Pay-per-download
Streaming payments
Fair creator compensation
Direct creator-to-consumer payments
How It Works
User Initiates Payment
User’s wallet signs a payment authorization using EIP-3009
Generate Payment Header
Client creates Base64-encoded payment header with signature
Send Request with Header
HTTP request includes payment header: X-Payment: <base64>
Server Verifies Payment
Server validates signature and payment details (no blockchain call)
Facilitator Settles
Facilitator executes on-chain settlement and pays gas
Confirmation
Server receives settlement confirmation and delivers service
Code Example: Client Side
import { Facilitator } from '@crypto.com/facilitator-client' ;
import { ethers } from 'ethers' ;
// 1. Initialize facilitator client
const facilitator = new Facilitator ({
network: 'cronos' ,
apiUrl: 'https://facilitator.crypto.com'
});
// 2. Get payment requirements
const requirements = await facilitator . getPaymentRequirements ({
amount: '10.00' ,
currency: 'USDC'
});
// 3. User signs payment with their wallet
const signer = new ethers . Wallet ( privateKey );
const paymentHeader = await facilitator . generatePaymentHeader ({
signer ,
amount: requirements . amount ,
recipient: requirements . recipient ,
nonce: requirements . nonce
});
// 4. Make API request with payment
const response = await fetch ( 'https://api.example.com/resource' , {
headers: {
'X-Payment' : paymentHeader
}
});
Code Example: Server Side
import { FacilitatorServer } from '@crypto.com/facilitator-server' ;
const facilitator = new FacilitatorServer ({
network: 'cronos' ,
merchantAddress: '0x...'
});
// Express middleware
app . use ( '/api/paid' , async ( req , res , next ) => {
const paymentHeader = req . headers [ 'x-payment' ];
if ( ! paymentHeader ) {
return res . status ( 402 ). json ({
error: 'Payment required' ,
payment_address: facilitator . getPaymentAddress (),
amount: '10.00' ,
currency: 'USDC'
});
}
try {
// Verify payment (no blockchain call, signature check only)
const payment = await facilitator . verifyPayment ( paymentHeader );
// Settle payment on-chain
const settlement = await facilitator . settlePayment ( payment );
// Payment confirmed, proceed
req . payment = payment ;
next ();
} catch ( error ) {
return res . status ( 402 ). json ({
error: 'Invalid payment' ,
details: error . message
});
}
});
Integration Patterns
Add payment requirements to existing REST APIs // Return 402 for unpaid requests
if ( ! hasValidPayment ) {
return res . status ( 402 ). json ({
error: 'Payment Required' ,
amount: '1.00' ,
currency: 'USDC'
});
}
Use Express middleware for automatic verification app . use ( '/premium' , x402Middleware ({
amount: '5.00' ,
currency: 'USDC'
}));
Receive settlement confirmations via webhooks app . post ( '/webhooks/payment' , ( req , res ) => {
const { txHash , amount , status } = req . body ;
// Handle confirmation
});
Autonomous AI agents making payments # Python AI agent
payment = agent.generate_payment(
amount = cost,
recipient = service_address
)
response = requests.get(
url,
headers = { 'X-Payment' : payment}
)
Benefits
For Users
✅ No CRO needed for gas
✅ Pay with stablecoins only
✅ Simple wallet signatures
✅ Fast payment processing
✅ Low transaction fees
For Developers
✅ No blockchain infrastructure
✅ Simple HTTP API integration
✅ No database required
✅ Automatic settlement
✅ Production-ready security
For Businesses
✅ Global payment acceptance
✅ Low payment processing fees
✅ No chargebacks
✅ Instant settlement
✅ Cryptographic security
Technical Details
EIP-3009 Signatures
x402 uses EIP-3009 for secure payment authorization:
// Signature components
{
from : '0x...' , // Payer address
to : '0x...' , // Recipient address
value : '1000000' , // Amount in token units
validAfter : 0 , // Validity start time
validBefore : MAX , // Validity end time
nonce : '0x...' , // Unique nonce
v , r , s // Signature components
}
Security Features
Replay Protection Unique nonces prevent transaction replay
Time Limits Payments expire after time window
Signature Verification Cryptographic proof of authorization
Amount Validation Exact amount verification
Best Practices
Security Considerations
Always verify signatures on server-side
Use HTTPS for all API communications
Implement rate limiting
Monitor for unusual payment patterns
Keep facilitator credentials secure
Use environment variables for sensitive data
Development Tips
Start with testnet integration
Test with small amounts first
Monitor facilitator status
Implement proper error handling
Log payment attempts for debugging
Use webhooks for reliable confirmations
Environment Setup
# Install dependencies
npm install @crypto.com/facilitator-client @crypto.com/facilitator-server ethers
# Set environment variables
export FACILITATOR_API_URL = "https://facilitator.crypto.com"
export MERCHANT_ADDRESS = "0x..."
export NETWORK = "cronos"
query_cronos_sdk_docs Find more SDK examples
get_contract_template Get smart contract templates
Resources
x402 Documentation Complete documentation
GitHub Examples Code examples repository
Facilitator API API reference
EIP-3009 Spec Technical specification