SDKs & CLI
Official client libraries and CLI tool for integrating PayDirect settlement on Base mainnet.
Method Reference
Quick comparison of available methods across SDKs
| Operation | TypeScript | Python | CLI |
|---|---|---|---|
| Create payment | createPayment() | create_payment() | payments create |
| Get payment | getPayment(id) | get_payment(id) | payments get |
| List payments | listPayments() | list_payments() | payments list |
| Cancel payment | cancelPayment(id) | cancel_payment(id) | payments cancel |
| Verify payment | verifyPayment(id) | verify_payment(id) | payments verify |
| Create webhook | createWebhook() | create_webhook() | webhooks create |
| List webhooks | listWebhooks() | list_webhooks() | webhooks list |
| Delete webhook | deleteWebhook(id) | delete_webhook(id) | webhooks delete |
| List keys | listKeys() | list_keys() | keys list |
| Create key | createKey() | create_key() | - |
| Revoke key | revokeKey(id) | revoke_key(id) | - |
| Verify webhook sig | verifyWebhookSignature() | verify_signature() | - |
| v0.3.0 — Payouts, Balance, Withdraw, Workspaces, Smart Wallets | |||
| Send payout | sendPayout() | — | - |
| List payouts | listPayouts() | — | - |
| Get balance | getBalance() | — | - |
| Withdraw | withdraw() | — | - |
| Create workspace | createWorkspace() | — | - |
| List workspaces | listWorkspaces() | — | - |
| Get workspace | getWorkspace() | — | - |
| Create smart wallet | createSmartWallet() | — | - |
| v0.4.0 — DEX Swaps | |||
| Get swap quote | getSwapQuote() | — | - |
| Execute swap | executeSwap() | — | - |
| Get smart wallet | getSmartWallet() | — | - |
| Set default wallet | setDefaultWallet() | — | - |
TypeScript
TypeScript SDK
@paydirect/sdk v0.3.0 — Official TypeScript/JavaScript client
Installation
npm install @paydirect/sdk
# or
pnpm add @paydirect/sdkInitialization
import { PayDirectClient } from "@paydirect/sdk";
const client = new PayDirectClient({
apiKey: "pd_test_abc123...",
baseUrl: "https://www.paydirect.com/api/v1", // optional, this is the default
timeoutMs: 30000, // optional, default 30s
});Create a Payment
const { payment, receivingAddress } = await client.createPayment({
tokenSymbol: "USDC", // "USDC" | "ETH" | "ADAO"
amount: "100.00",
merchantWallet: "0xYourBase...",
description: "Invoice #1234", // optional
metadata: { orderId: "ORD_1" }, // optional
idempotencyKey: "order-1-v1", // optional
expiresInMinutes: 60, // optional, default 60
});List and Get Payments
// List with filters
const { payments, total } = await client.listPayments({
status: "forwarded",
environment: "sandbox",
limit: 20,
offset: 0,
});
// Get by ID
const { payment } = await client.getPayment("a1b2c3d4-...");
// Cancel
const { payment: cancelled } = await client.cancelPayment("a1b2c3d4-...");
// Verify settlement
const { verified, payment: p } = await client.verifyPayment("a1b2c3d4-...");Webhooks
// Create
const { webhook } = await client.createWebhook(
"https://yourapp.com/webhooks",
["payment.forwarded", "payment.failed"]
);
console.log(webhook.signingSecret); // "whsec_..." — store this!
// List
const { webhooks } = await client.listWebhooks();
// Delete
await client.deleteWebhook("7");Webhook Signature Verification
// Static method — no client instance needed
const isValid = PayDirectClient.verifyWebhookSignature(
"whsec_...", // signing secret
rawRequestBody, // string
signatureHeader // X-PayDirect-Signature value
);Error Handling
import { PayDirectError } from "@paydirect/sdk";
try {
await client.createPayment({ ... });
} catch (err) {
if (err instanceof PayDirectError) {
console.log(err.message); // human-readable error
console.log(err.status); // HTTP status code (408 = timeout)
console.log(err.data); // raw response body
}
}v0.3.0
Payouts
// Send a payout to any address
const { payout } = await client.sendPayout({
tokenSymbol: "ADAO",
amount: "500",
destinationAddress: "0xRecipient...",
walletType: "smart_wallet", // optional: "eoa" | "smart_wallet"
description: "Agent payment",
});
console.log(payout.txHash);
// List payout history
const { payouts, total } = await client.listPayouts({ limit: 50 });v0.3.0
Wallet Balance
const balance = await client.getBalance();
console.log(balance.eth, balance.usdc, balance.adao);
console.log(balance.defaultWalletType);
// Smart wallet balance (if provisioned)
if (balance.smartWallet) {
console.log(balance.smartWallet.adao);
}v0.3.0
Withdraw
const result = await client.withdraw({
tokenSymbol: "USDC",
amount: "50", // omit for full balance
walletType: "smart_wallet",
});
console.log(result.explorerUrl);v0.3.0
Workspaces (Admin)
// Requires admin secret as apiKey
const admin = new PayDirectClient({
apiKey: process.env.PAYDIRECT_ADMIN_SECRET!,
});
// Create workspace for a platform user
const ws = await admin.createWorkspace({
name: "alice-workspace",
ownerEmail: "alice@example.com",
platform: "myplatform",
settlementWallet: "0xSettlement...",
});
console.log(ws.workspaceId, ws.apiKeys.live);
// List workspaces
const { workspaces } = await admin.listWorkspaces({ platform: "myplatform" });
// Get workspace details
const info = await admin.getWorkspace(ws.workspaceId);v0.3.0
Smart Wallets
// Create smart wallet (ERC-4337, gasless)
const result = await client.createSmartWallet(workspaceId, {
setDefault: true,
});
console.log(result.smartWallet.address);
// Get wallet info
const info = await client.getSmartWallet(workspaceId);
console.log(info.eoa, info.smartWallet, info.defaultWalletType);
// Switch default wallet type
await client.setDefaultWallet(workspaceId, "smart_wallet");Python
Python SDK
paydirect - Official Python client
Installation
pip install paydirectInitialization
from paydirect import PayDirectClient
client = PayDirectClient(
api_key="pd_test_abc123...",
base_url="https://www.paydirect.com/api/v1", # optional default
)Create a Payment
result = client.create_payment(
token_symbol="USDC",
amount="100.00",
merchant_wallet="0xYourBase...",
description="Invoice #1234", # optional
metadata={"orderId": "ORD_1"}, # optional
idempotency_key="order-1-v1", # optional
expires_in_minutes=60, # optional
)
payment = result["payment"]
receiving_address = result["receivingAddress"]List, Get, Cancel, Verify
# List
result = client.list_payments(status="forwarded", limit=20)
# Get
result = client.get_payment("a1b2c3d4-...")
# Cancel
result = client.cancel_payment("a1b2c3d4-...")
# Verify
result = client.verify_payment("a1b2c3d4-...")
print(result["verified"]) # TrueWebhooks
# Create
result = client.create_webhook(
url="https://yourapp.com/webhooks",
events=["payment.forwarded", "payment.failed"]
)
# List
result = client.list_webhooks()
# Delete
result = client.delete_webhook("7")Webhook Signature Verification
from paydirect.webhooks import verify_signature
is_valid = verify_signature(
secret="whsec_...",
payload=raw_request_body,
signature=request.headers["X-PayDirect-Signature"]
)Error Handling
from paydirect import PayDirectError
try:
client.create_payment(...)
except PayDirectError as e:
print(e) # error message
print(e.status) # HTTP status code
print(e.data) # raw response bodyCLI
Command Line Tool
paydirect CLI for terminal-based API interaction
Installation
npm install -g @paydirect/cli
# or use npx
npx @paydirect/cli <command>Configuration
# Option 1: Initialize config file
paydirect init pd_test_abc123...
# Option 2: Environment variable
export PAYDIRECT_API_KEY=pd_test_abc123...
export PAYDIRECT_BASE_URL=https://www.paydirect.com/api/v1 # optionalThe init command creates a .paydirect.json file in the current directory.
Commands
| Command | Description |
|---|---|
| init <key> | Save API key to .paydirect.json |
| payments create --token=USDC --amount=100 --wallet=0x... | Create a payment |
| payments list [--status=pending] | List payments with optional filter |
| payments get <id> | Get payment details |
| payments cancel <id> | Cancel a pending payment |
| payments verify <id> | Verify payment settlement |
| webhooks list | List webhooks |
| webhooks create <url> [events] | Register a webhook |
| webhooks delete <id> | Remove a webhook |
| keys list | List API keys |
| status | Show recent payments |
Examples
# Create a 50 USDC payment
paydirect payments create --token=USDC --amount=50 --wallet=0xABC...
# List pending payments
paydirect payments list --status=pending
# Verify a payment
paydirect payments verify a1b2c3d4-...
# Register a webhook for forwarded events
paydirect webhooks create https://myapp.com/hooks payment.forwarded,payment.failedAI Framework Packages
NEW
Pre-built tools for AI agents to make payments, swap tokens, and manage wallets.
@paydirect/ai-sdk Vercel AI SDK
npm install @paydirect/ai-sdk ai @ai-sdk/openai zodimport { createPayDirectTools } from "@paydirect/ai-sdk";
import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";
const tools = createPayDirectTools({
apiKey: process.env.PAYDIRECT_API_KEY!,
});
const { text } = await generateText({
model: openai("gpt-4o"),
tools,
maxSteps: 5,
prompt: "Check my balance then swap 10 USDC for ETH",
});@paydirect/langchain LangChain
npm install @paydirect/langchain @langchain/coreimport { createLangChainTools } from "@paydirect/langchain";
const tools = await createLangChainTools({
apiKey: process.env.PAYDIRECT_API_KEY!,
});
// Pass tools to your LangChain agentAvailable tools: getBalance, sendPayout, createPayment, getPayment, listPayments, getSwapQuote, executeSwap, withdraw
x402 Protocol (by Coinbase)
Optional
HTTP-native payments for AI agents. Install these alongside the PayDirect SDK if you want to add x402 pay-per-request to your API endpoints.
Server Side (Protect API Routes)
npm install x402-next @x402/core @x402/evmClient Side (Agent Auto-Pay)
npm install @x402/fetch @x402/core @x402/evmQuick Example
// Protect a route with x402
import { withX402 } from "x402-next"
export const GET = withX402(
handler,
"0xYourWallet",
{ price: "$0.01", network: "base-sepolia" },
{ url: "https://x402.org/facilitator" }
)See the x402 Payments Guide for full setup instructions.
