Documentation

Everything you need to integrate x402 payments into your applications with real Solana transactions.

Full Phantom wallet integration | Real SOL payments | Auto-refund system

Getting Started

Quick Start Guide

What is x402?

The x402 extension brings cryptocurrency payments to the Agent-to-Agent (A2A) protocol, enabling agents to monetize their services through on-chain payments. This extension revives the spirit of HTTP 402 "Payment Required" for the decentralized agent ecosystem.

Key Features:

  • • Real Solana blockchain transactions
  • • Full Phantom wallet integration
  • • Instant SOL payments on mainnet
  • • Automatic refund system
  • • Transaction verification on Solscan
  • • No API keys required

Payment Flow

1

Payment Required

Merchant agent responds with payment-required message

2

Payment Submitted

Client signs payment details and sends payment-submitted message

3

Payment Completed

Merchant verifies payment and delivers service

Quick Example

// Python example
from x402_a2a import PaymentClient

client = PaymentClient()
payment = client.create_payment(
    amount=1000000,  # 1 SOL in lamports
    token="SOL",
    merchant_id="agent123"
)

result = client.submit_payment(payment)
if result.success:
    print("Payment successful!")

This example shows how to create and submit a payment using our Python SDK.

API Reference

API Documentation

Message Types

payment-required

Sent by merchant agent when payment is required for a service.

{
  "type": "payment-required",
  "amount": "1000000",
  "token": "SOL",
  "merchant_id": "agent123",
  "service_id": "ai-inference",
  "expires_at": "2024-01-01T12:00:00Z"
}

payment-submitted

Sent by client agent with signed payment details.

{
  "type": "payment-submitted",
  "payment_id": "pay_123",
  "signature": "0x...",
  "transaction_hash": "0x...",
  "amount": "1000000",
  "token": "SOL"
}

payment-completed

Sent by merchant agent after successful payment verification.

{
  "type": "payment-completed",
  "payment_id": "pay_123",
  "service_result": {...},
  "delivered_at": "2024-01-01T12:01:00Z"
}

Error Codes

INSUFFICIENT_FUNDS400
INVALID_SIGNATURE401
PAYMENT_EXPIRED408
NETWORK_ERROR500

Webhook Events

payment.created
payment.pending
payment.completed
payment.failed
SDKs & Libraries

Language-Specific SDKs

Installation

Python

pip install x402-a2a

Supports Python 3.8+ with async/await

JavaScript/TypeScript

npm install @a2a/x402-sdk

Works with Node.js, React, and vanilla JS

Python SDK

Features

  • • Async/await support
  • • Built-in wallet integration
  • • Multi-network support
  • • Comprehensive error handling
import asyncio
from x402_a2a import PaymentClient

async def main():
    client = PaymentClient()
    payment = await client.create_payment(
        amount=1000000,
        token="SOL"
    )
    result = await client.submit_payment(payment)
    print(f"Payment status: {result.status}")

asyncio.run(main())

JavaScript SDK

Features

  • • TypeScript definitions
  • • React components included
  • • Browser & Node.js support
  • • Web3 wallet integration
import { PaymentClient } from '@a2a/x402-sdk'

const client = new PaymentClient()
const payment = await client.createPayment({
  amount: '1000000',
  token: 'SOL'
})

const result = await client.submitPayment(payment)
console.log('Payment status:', result.status)

Supported Networks

S

Solana

E

Ethereum

P

Polygon

A

Avalanche