Content
# A2A x402 SDK
[](https://badge.fury.io/js/@a2a%2Fx402-sdk)
[](https://opensource.org/licenses/MIT)
[](https://www.typescriptlang.org/)
> **Solana-first, multi-network x402 facilitator SDK**
The A2A x402 SDK brings cryptocurrency payments to the Agent-to-Agent (A2A) protocol, enabling agents to monetize their services through on-chain payments. This SDK revives the spirit of HTTP 402 "Payment Required" for the decentralized agent ecosystem.
## 🚀 Features
- **🔗 Multi-Network Support**: Solana, EVM chains (Base, Avalanche, Sei, IoTeX)
- **⚡ Instant Payments**: Process payments in under a second
- **🔒 No API Keys**: Direct blockchain integration
- **💰 Microtransactions**: Support for payments as low as $0.01
- **🔄 Built-in Refunds**: Automatic refund mechanisms
- **📱 Multiple Languages**: JavaScript, TypeScript, Python, Go
- **🛡️ Secure**: Wallet-based authentication
## 📦 Installation
### JavaScript/TypeScript
```bash
npm install @a2a/x402-sdk
# or
yarn add @a2a/x402-sdk
# or
pnpm add @a2a/x402-sdk
```
### Python
```bash
pip install a2a-x402-sdk
```
### Go
```bash
go get github.com/a2a/x402-sdk-go
```
## 🚀 Quick Start
### JavaScript/TypeScript
```typescript
import { X402Client } from '@a2a/x402-sdk'
// Initialize the client
const client = new X402Client({
network: 'solana-devnet', // or 'solana-mainnet', 'base', 'avalanche', etc.
rpcUrl: 'https://api.devnet.solana.com'
})
// Create a payment request
const payment = await client.createPayment({
amount: 0.001, // SOL
recipient: 'So11111111111111111111111111111111111111112',
memo: 'x402 payment test'
})
// Process the payment
const result = await client.processPayment(payment)
console.log('Payment successful:', result.signature)
```
### Python
```python
from a2a_x402_sdk import X402Client
# Initialize the client
client = X402Client(
network='solana-devnet',
rpc_url='https://api.devnet.solana.com'
)
# Create and process payment
payment = client.create_payment(
amount=0.001,
recipient='So11111111111111111111111111111111111111112',
memo='x402 payment test'
)
result = client.process_payment(payment)
print(f'Payment successful: {result.signature}')
```
### Go
```go
package main
import (
"fmt"
"github.com/a2a/x402-sdk-go"
)
func main() {
client := x402.NewClient(x402.Config{
Network: "solana-devnet",
RPCURL: "https://api.devnet.solana.com",
})
payment := client.CreatePayment(x402.PaymentRequest{
Amount: 0.001,
Recipient: "So11111111111111111111111111111111111111112",
Memo: "x402 payment test",
})
result, err := client.ProcessPayment(payment)
if err != nil {
panic(err)
}
fmt.Printf("Payment successful: %s\n", result.Signature)
}
```
## 🌐 Supported Networks
| Network | Status | RPC Endpoint |
|---------|--------|--------------|
| Solana (Mainnet) | ✅ Live | `https://api.mainnet-beta.solana.com` |
| Solana (Devnet) | ✅ Live | `https://api.devnet.solana.com` |
| Base | 🚧 Coming Soon | - |
| Avalanche | 🚧 Coming Soon | - |
| Sei | 🚧 Coming Soon | - |
| IoTeX | 🚧 Coming Soon | - |
## 📚 API Reference
### X402Client
#### Constructor Options
```typescript
interface X402Config {
network: 'solana-mainnet' | 'solana-devnet' | 'base' | 'avalanche' | 'sei' | 'iotex'
rpcUrl?: string
timeout?: number
retries?: number
}
```
#### Methods
##### `createPayment(request: PaymentRequest): Promise<Payment>`
Creates a new payment request.
```typescript
interface PaymentRequest {
amount: number
recipient: string
memo?: string
token?: string // Default: 'SOL'
}
```
##### `processPayment(payment: Payment): Promise<PaymentResult>`
Processes a payment and returns the result.
```typescript
interface PaymentResult {
success: boolean
signature?: string
error?: string
blockTime?: number
}
```
##### `verifyPayment(signature: string): Promise<PaymentVerification>`
Verifies a payment by its signature.
```typescript
interface PaymentVerification {
verified: boolean
amount?: number
recipient?: string
blockTime?: number
}
```
## 🔧 Advanced Usage
### Custom Wallet Integration
```typescript
import { X402Client } from '@a2a/x402-sdk'
const client = new X402Client({
network: 'solana-mainnet',
wallet: {
provider: window.solana, // Phantom, Solflare, etc.
autoConnect: true
}
})
```
### Error Handling
```typescript
try {
const result = await client.processPayment(payment)
if (result.success) {
console.log('Payment successful:', result.signature)
} else {
console.error('Payment failed:', result.error)
}
} catch (error) {
console.error('Unexpected error:', error)
}
```
### Event Listeners
```typescript
client.on('payment:created', (payment) => {
console.log('Payment created:', payment.id)
})
client.on('payment:processed', (result) => {
console.log('Payment processed:', result.signature)
})
client.on('payment:failed', (error) => {
console.error('Payment failed:', error)
})
```
## 🧪 Testing
```bash
# Run tests
npm test
# Run tests with coverage
npm run test:coverage
# Run integration tests
npm run test:integration
```
## 📖 Examples
Check out the [examples directory](./examples/) for complete working examples:
- [Basic Payment](./examples/basic-payment/)
- [React Integration](./examples/react-integration/)
- [Node.js Server](./examples/node-server/)
- [Python Flask](./examples/python-flask/)
## 🤝 Contributing
We welcome contributions! Please see our [Contributing Guide](./CONTRIBUTING.md) for details.
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
## 📄 License
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.
## 🆘 Support
- 📖 [Documentation](https://docs.a2a-x402.network)
- 💬 [Discord Community](https://discord.gg/a2a-x402)
- 🐛 [Report Issues](https://github.com/a2a/x402-sdk/issues)
- 💡 [Feature Requests](https://github.com/a2a/x402-sdk/discussions)
## 🙏 Acknowledgments
- Solana Foundation for the amazing blockchain infrastructure
- The A2A community for feedback and contributions
- All the developers building the future of agent-to-agent commerce
---
<div align="center">
<strong>Built with ❤️ by the A2A Team</strong>
<br>
<a href="https://a2a-x402.network">Website</a> •
<a href="https://docs.a2a-x402.network">Docs</a> •
<a href="https://discord.gg/a2a-x402">Discord</a>
</div>