Debugging Server Issues
Learning Objectives
- Inspect PAYMENT-REQUIRED and PAYMENT-RESPONSE headers
- Identify common verification errors
- Diagnose settlement failures
- Use lifecycle hooks for debugging
- Troubleshoot facilitator connection issues
Common Server Issues
When building x402 servers, you may encounter:
Configuration Issues:
Verification Issues:
Settlement Issues:
Debugging Tool 1: Inspecting Headers
The PAYMENT-REQUIRED header tells clients what payment is needed. Decode it to debug:
# Make a request without payment
curl -i http://localhost:4021/weather
# Response:
HTTP/1.1 402 Payment Required
PAYMENT-REQUIRED: eyJ4NDAyVmVyc2lvbiI6MiwiZXJyb3IiOiJQYXltZW50IHJlcXVpcmVkIi...
# Decode the header
echo "eyJ4NDAyVmVyc2lvbiI6MiwiZXJyb3IiOiJQYXltZW50IHJlcXVpcmVkIi..." | base64 -d | jq{
"x402Version": 2,
"error": "Payment required",
"resource": {
"url": "http://localhost:4021/weather",
"description": "Weather data",
"mimeType": "application/json"
},
"accepts": [
{
"scheme": "exact",
"network": "eip155:84532",
"amount": "1000",
"asset": "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
"payTo": "0x...",
"maxTimeoutSeconds": 300
}
]
}network, amount, and payTo are correct. The amount is in atomic units (1000 = 0.001 USDC for 6 decimal tokens).Common Error 1: Wrong Network Identifier
Error: Unsupported network: eip155:1
Cause: You configured a network that isn't registered with your resource server.
Solution: Make sure you registered the scheme for that network:
// ❌ Wrong - network not registered
const server = new x402ResourceServer(facilitatorClient);
// Only EVM scheme registered for Base Sepolia by default
// ✅ Correct - explicitly register networks
const server = new x402ResourceServer(facilitatorClient);
registerExactEvmScheme(server); // Registers all EVM networks
// OR
server.register('eip155:84532', new ExactEvmScheme()); // Specific networkCommon Error 2: Invalid Payment Signature
Error: Payment verification failed: Invalid signature
Cause: The payment signature doesn't match the requirements or is malformed.
Solution: Check that client and server requirements match:
// Add onBeforeVerify hook to inspect requirements
const server = new x402ResourceServer(facilitatorClient)
.register('eip155:84532', new ExactEvmScheme())
.onBeforeVerify(async (context) => {
console.log('Verifying payment:');
console.log('- Network:', context.requirements.network);
console.log('- Amount:', context.requirements.amount);
console.log('- PayTo:', context.requirements.payTo);
console.log('- Signature from:', context.signature.from);
return undefined;
});Common Error 3: Settlement Timeout
Error: Settlement timed out after 300 seconds
Cause: The on-chain transaction took too long or failed.
Solution: Check facilitator status and network congestion:
// Add settlement hooks to monitor progress
const server = new x402ResourceServer(facilitatorClient)
.register('eip155:84532', new ExactEvmScheme())
.onBeforeSettle(async (context) => {
console.log('Starting settlement...');
return undefined;
})
.onAfterSettle(async (context) => {
console.log('✅ Settlement succeeded:', context.result.transaction);
return undefined;
})
.onSettleFailure(async (context) => {
console.error('❌ Settlement failed:', context.error.message);
// Check error type
if (context.error.message.includes('timeout')) {
console.error('Network congestion or facilitator issue');
}
return undefined;
});Common Error 4: Facilitator Connection Failed
Error: Failed to connect to facilitator
Cause: Wrong facilitator URL or facilitator is down.
Solution:
// Test facilitator connection
const facilitatorClient = new HTTPFacilitatorClient({
url: 'https://api.cdp.coinbase.com/platform/v2/x402'
});
// Add error handling
try {
const server = new x402ResourceServer(facilitatorClient);
console.log('✅ Facilitator connected');
} catch (error) {
console.error('❌ Facilitator connection failed:', error);
// Check URL, network connectivity
}https://x402.org/facilitator. For mainnet, use https://api.cdp.coinbase.com/platform/v2/x402.Debugging Checklist
When things go wrong:
Debug a Broken Server
Fix common configuration errors in an x402 server
Requirements:
Correct facilitator URL
Facilitator URL is correct
Scheme registered
EVM scheme is registered
Valid EVM address
PayTo address is valid EVM format