Code Examples
Get started quickly with these ready-to-use code examples
TypeScript: HTTP Interceptor (Easiest)
Automatically handles all 402 responses. Just set it up once and forget about it.
import { HTTPInterceptor } from '@NexromDEX/agent';
// Setup once
const interceptor = new HTTPInterceptor({
apiUrl: 'https://api.NexromDEX.com',
walletSecretKey: process.env.WALLET_SECRET_KEY,
autoSwap: true,
});
// Now all fetch() calls handle 402 automatically!
const response = await fetch('https://premium-api.com/data');
const data = await response.json(); // Works seamlessly!TypeScript: Manual x402 Handling
More control over the payment flow. Handle 402 responses manually.
import { X402AutoPayAgent } from '@NexromDEX/agent';
const agent = new X402AutoPayAgent({
apiUrl: 'https://api.NexromDEX.com',
walletSecretKey: process.env.WALLET_SECRET_KEY,
autoSwap: true,
});
// Make API call
let response = await fetch('https://premium-api.com/data');
// Handle 402 if needed
if (response.status === 402) {
const result = await agent.handle402(response);
if (result.success) {
// Retry original request
response = await fetch('https://premium-api.com/data');
}
}
const data = await response.json();Python: x402 Auto-Pay
Python integration for handling x402 payments automatically.
from NexromDEX import NexromDEX
import requests
# Initialize
dex = NexromDEX(
wallet_path="wallet.json",
api_url="https://api.NexromDEX.com"
)
# Make API call
response = requests.get('https://premium-api.com/data')
# Handle 402 if needed
if response.status_code == 402:
payment_result = dex.handle_402_payment(response)
if payment_result['success']:
# Retry original request
response = requests.get('https://premium-api.com/data')
if response.ok:
data = response.json()
print('Data received:', data)REST API: Get Quote
Get a swap quote before executing the transaction.
# Get quote for swapping 1 SOL to USDC
curl "https://api.NexromDEX.com/api/quote?\
input_mint=So11111111111111111111111111111111111111112&\
output_mint=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v&\
amount=1000000000"
# Response includes:
# - output_amount: Amount you'll receive
# - fee_amount: NexromDEX fee (0.1%)
# - output_after_fee: Final amount after feeREST API: Build Swap Transaction
Build an unsigned transaction. Sign it client-side and send it.
curl -X POST https://api.NexromDEX.com/api/swap/build \
-H "Content-Type: application/json" \
-d '{
"wallet_address": "YOUR_WALLET_ADDRESS",
"input_mint": "So11111111111111111111111111111111111111112",
"output_mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"amount": "1000000000"
}'
# Returns unsigned transaction (base64)
# Sign it with your wallet, then send via Solana RPCMore Resources
Ready to Integrate?
Start building agents that handle x402 payments automatically. Check out our developer documentation.
Get Started →