Installation & Usage
Python
Install
uv python install 3.13
uv sync --frozen
Deploy a Paid Agent (Seller)
from google.adk import Agent
from ampersend_sdk.a2a.server import to_a2a, make_x402_before_agent_callback
agent = Agent(
name="facts_agent",
tools=[google_search],
before_agent_callback=make_x402_before_agent_callback(
price="$0.001",
network="base-sepolia",
pay_to_address="0xYourWallet..."
)
)
a2a_app = to_a2a(agent, port=8001)
Use a Paid Agent (Buyer)
from ampersend_sdk.a2a.client import X402RemoteA2aAgent
from ampersend_sdk.x402.treasurers.naive import NaiveTreasurer
from ampersend_sdk.x402.wallets.account import AccountWallet
wallet = AccountWallet(private_key="0x...")
treasurer = NaiveTreasurer(wallet)
agent = X402RemoteA2aAgent(
treasurer=treasurer,
agent_url="http://localhost:8001"
)
result = await agent.run("your query")
TypeScript
Install
pnpm install
pnpm build
Deploy a Paid MCP Server
import { FastMCP } from "fastmcp";
import { withX402Payment } from "@edgeandnode/ampersend-sdk/mcp/server/fastmcp";
const server = new FastMCP("my-paid-service");
server.addTool({
name: "expensive_operation",
execute: withX402Payment({
onExecute: () => ({
scheme: "exact",
amount: "1000000",
asset: "0xUSDC",
network: "base-sepolia",
payTo: "0xYourWallet",
}),
onPayment: () => ({ success: true }),
})(async () => {
return "result";
}),
});
await server.start({ httpStream: { port: 8080 } });
Use a Paid MCP Service
import { X402McpClient } from "@edgeandnode/ampersend-sdk/mcp/client";
import { AccountWallet, NaiveTreasurer } from "@edgeandnode/ampersend-sdk/x402";
const wallet = AccountWallet.fromPrivateKey("0x...");
const treasurer = new NaiveTreasurer(wallet);
const client = new X402McpClient({
serverUrl: "http://localhost:8080/mcp",
treasurer,
});
await client.connect();
const result = await client.callTool("expensive_operation", {});