A complete TypeScript implementation of the Python x402 payment protocol extension for A2A (Agent-to-Agent) communication. Enable your AI agents to request, verify, and settle crypto payments seamlessly.
a2a-x402 is an early-stage TypeScript project in the AI payments / x402 ecosystem, focused on a2a, a2a-x402, agents, ai. It currently has 4 GitHub stars and 0 forks, and sits alongside related tools like x402, daydreams, a2a-go, lucid-agents, os-moda, a2a-x402-typescript.
A complete TypeScript implementation of the Python x402 payment protocol extension for A2A (Agent-to-Agent) communication. Enable your AI agents to request, verify, and settle crypto payments seamlessly.
npm install a2a-x402
import { x402PaymentRequiredException } from 'a2a-x402';
// In your agent tool, throw an exception to request payment:
throw new x402PaymentRequiredException(
"Payment required for product",
{
scheme: "exact",
network: "base-sepolia",
asset: "0x036CbD53842c5426634e7929541eC2318f3dCF7e", // USDC
payTo: "0xYourWalletAddress",
maxAmountRequired: "1000000", // 1 USDC in atomic units
resource: "/buy-product",
description: "Payment for banana",
mimeType: "application/json",
maxTimeoutSeconds: 1200,
}
);
import { processPayment, x402Utils } from 'a2a-x402';
import { Wallet } from 'ethers';
const wallet = new Wallet(privateKey);
const utils = new x402Utils();
// Get payment requirements from task
const paymentRequired = utils.getPaymentRequirements(task);
// Sign the payment
const paymentPayload = await processPayment(
paymentRequired.accepts[0],
wallet
);
The library provides a complete implementation of the x402 payment protocol:
Abstract base classes for building payment-enabled agents:
x402ServerExecutor - For merchant/service provider agentsx402ClientExecutor - For client/wallet agentsx402PaymentRequiredExceptionThe main exception class for requesting payments:
// Simple payment request
throw new x402PaymentRequiredException(
"Payment required",
{
scheme: "exact",
network: "base-sepolia",
asset: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
payTo: "0xYourAddress",
maxAmountRequired: "1000000",
resource: "/service",
description: "Service payment",
mimeType: "application/json",
maxTimeoutSeconds: 1200,
}
);
// Multiple payment options
throw new x402PaymentRequiredException(
"Choose payment tier",
[basicTier, premiumTier, ultraTier]
);
processPayment()Sign a payment with a wallet:
import { processPayment } from 'a2a-x402';
import { Wallet } from 'ethers';
const wallet = new Wallet(privateKey);
const paymentPayload = await processPayment(requirements, wallet);
x402UtilsUtility class for managing payment state:
import { x402Utils } from 'a2a-x402';
const utils = new x402Utils();
// Get payment status
const status = utils.getPaymentStatus(task);
// Get payment requirements
const requirements = utils.getPaymentRequirements(task);
// Record payment success
utils.recordPaymentSuccess(task, settleResponse);
x402ServerExecutorBase class for merchant agents:
import { x402ServerExecutor } from 'a2a-x402';
class MyMerchantExecutor extends x402ServerExecutor {
async verifyPayment(payload, requirements) {
// Verify signature and payment details
}
async settlePayment(payload, requirements) {
// Execute on-chain settlement
}
}
x402ClientExecutorBase class for client agents:
import { x402ClientExecutor } from 'a2a-x402';
class MyClientExecutor extends x402ClientExecutor {
async handlePaymentRequired(error, task) {
// Process payment requirements
}
}
This repository includes two fully functional example agents that demonstrate end-to-end payment flows:
A payment-enabled orchestrator agent that can interact with merchants and process payments.
Install and run:
cd client-agent
npm install
cp .env.example .env
# Edit .env with your API keys and wallet
npm run dev
Features:
See client-agent/README.md for details.
A service provider agent that requests payments, verifies signatures, and settles transactions.
Install and run:
cd merchant-agent
npm install
cp .env.example .env
# Edit .env with your API keys and wallet
npm run dev
Features:
See merchant-agent/README.md for details.
Run both agents to see the complete payment flow:
Terminal 1 - Merchant:
cd merchant-agent && npm run dev
Terminal 2 - Client:
cd client-agent && npm run dev
Client terminal:
You: I want to buy a banana
Agent: The merchant is requesting 1.000000 USDC for a banana. Proceed?
You: yes
Agent: Payment completed! Transaction: 0x...
If you want to modify the library locally and test with your agents:
# Clone and build the library
git clone <repo-url>
cd a2a-x402-typescript/x402_a2a
npm install
npm run build
# Link for local development
cd ../your-project
npm install a2a-x402
The example agents include test scripts:
# Test merchant payment flow
cd merchant-agent
npm run test:payment
# Test client agent
cd client-agent
npm run dev
The library works with any EVM-compatible network. The example agents use:
84532https://sepolia.base.org0x036CbD53842c5426634e7929541eC2318f3dCF7e8453https://mainnet.base.org0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913Private key management:
.env filesThe example client agent uses a 10% buffer for approvals:
const approvalAmount = (amount * 110n) / 100n;
Always review approval amounts before signing transactions.
Apache-2.0 - See LICENSE for details
npm install a2a-x402Contributions welcome! Please feel free to submit a Pull Request.
💸 Enable seamless, low-cost digital dollar payments with x402—zero fees, instant settlement, and no high minimums for all users.
Daydreams is a set of tools for building agents for commerce
Golang SDK for A2A Protocol
Lucid Agents Commerce SDK. Bootstrap AI agents in 60 seconds that can pay, sell, and participate in agentic commerce supply chains. Our protocol agnostic SDK provides CLI-generated templates and drop-in adapters for Hono, Express, Next.js, and TanStack, giving you instant access to crypto/fiat payment rails (AP2, A2A, x402, ERC8004).
An operating system built for AI agents — talk to your NixOS server instead of SSH-ing in. Typed, audited tool access with atomic rollback on every change. Research-grade; run it on a disposable box, not production.
A complete TypeScript implementation of the Python x402 payment protocol extension for A2A (Agent-to-Agent) communication. Enable your AI agents to request, verify, and settle crypto payments seamlessly.
A local-first AI agent with persistent memory, emotional intelligence, and a peer-to-peer skills economy.
The trust layer for agent-to-agent commerce — natural-language mandates, ERC-7710 delegated permissions, x402 payments, escrow, and dispute resolution as one open, catch-all Agent Skill / Claude Code plugin.
Agent behavior that compiles
The A2A 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.
Aser is a lightweight, self-assembling AI Agent frame.
A small, powerful, open-source CLI coding agent that works with open models.