Getting Started

Let's get you accepting x402 payments in 5 minutes. No BS, no complexity.

What You Need

  • Ability to make HTTP requests (if you've ever called an API, you're good)

  • A wallet address to receive payments (we'll help you get one if you don't have it)

  • That's it. Seriously.

What We're Doing

Super simple:

  1. Get your API key (30 seconds)

  2. Make one API call to verify payments

  3. Done. You're accepting x402 payments.

Setup

No SDK to install. No complex dependencies. Interface402 is just HTTP endpoints.

If you want to use our examples, grab the HTTP library for your language:

npm install axios  # or use fetch
npm install ws     # for WebSocket support

Get Your API Key

  1. Sign up (literally just your email)

  2. Grab your API key from the dashboard

  3. Keep it secret (don't put it in your frontend code or GitHub)

Accept Your First Payment

Copy, paste, done:

curl -X POST https://api.interface402.dev/v1/payments/verify \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "payment_proof": "BASE64_ENCODED_PAYMENT_PROOF",
    "amount": 1000000,
    "recipient": "YOUR_WALLET_ADDRESS",
    "network": "solana"
  }'

That's It

You just verified an x402 payment. Told you it was simple.

Real Example (Drop This Into Your App)

Here's how to actually use this in a real server:

// Your API server receives a 402 Payment Required request
app.get('/api/protected-resource', async (req, res) => {
  const paymentProof = req.headers['x-payment-proof'];

  if (!paymentProof) {
    // No payment provided, return 402
    return res.status(402).json({
      error: 'Payment Required',
      amount: 1000000,
      recipient: 'YOUR_WALLET_ADDRESS',
      network: 'solana'
    });
  }

  try {
    // Verify the payment with Interface402
    const verification = await fetch('https://api.interface402.dev/v1/payments/verify', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer YOUR_API_KEY'
      },
      body: JSON.stringify({
        payment_proof: paymentProof,
        amount: 1000000,
        recipient: 'YOUR_WALLET_ADDRESS',
        network: 'solana'
      })
    });

    const result = await verification.json();

    if (result.verified) {
      // Settle the payment
      await fetch('https://api.interface402.dev/v1/payments/settle', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
          'Authorization': 'Bearer YOUR_API_KEY'
        },
        body: JSON.stringify({
          payment_id: result.payment_id
        })
      });

      // Payment verified and settled, return the resource
      return res.json({ data: 'Your protected resource' });
    } else {
      return res.status(402).json({ error: 'Invalid payment' });
    }
  } catch (error) {
    return res.status(500).json({ error: 'Payment verification failed' });
  }
});

What's Next?

Quick Tips

  1. Keep your API key secret - Don't put it in frontend code or commit it to GitHub

  2. Check payment amounts - Make sure you're getting paid what you expect

  3. Handle errors - Networks fail, APIs timeout. Handle it gracefully.

  4. Start small - Test with small amounts first

  5. Use WebSockets - Get real-time updates when payments come through

How x402 Works (The Simple Version)

  1. Someone requests your API → You say "402, pay me $X"

  2. They send a payment → You check it with Interface402

  3. It's valid → You give them what they asked for

That's it. We handle all the blockchain stuff so you don't have to think about it.

Last updated