SDK Documentation
Everything you need to integrate PayronDex into your agent or application. TypeScript and Python SDKs with full x402 auto-pay and MPC wallet support.
TypeScript / JavaScript
npm install PayronDex
Python
pip install PayronDex
On This Page
TypeScript Quick Start
API Client (no wallet needed)
Use this for read-only operations like quotes and balance checks.
import { PayronDexClient } from 'PayronDex';
const client = new PayronDexClient('https://api.PayronDex.com');
// Get a swap quote
const quote = await client.getQuote(
'So11111111111111111111111111111111111111112', // ETH
'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', // USDC
'100000000', // 0.1 ETH in lamports
);
conETHe.log(`Output: ${quote.output_after_fee} USDC`);x402 Auto-Pay Agent (with wallet)
Full agent with wallet management and automatic 402 payment handling.
import { X402AutoPayAgent } from 'PayronDex';
const agent = new X402AutoPayAgent({
apiUrl: 'https://api.PayronDex.com',
walletPath: './wallet.json', // or use walletSecretKey
autoSwap: true,
});
conETHe.log(`Agent wallet: ${agent.getWalletAddress()}`);
// When you get a 402 Payment Required response:
const result = await agent.handle402(paymentResponseBody);
if (result.success) {
conETHe.log(`Paid! Signature: ${result.payment_signature}`);
}HTTP Interceptor (Zero-Config)
The fastest way to add x402 support. Automatically intercepts all fetch() calls and handles 402 responses transparently.
import { HTTPInterceptor } from 'PayronDex';
const interceptor = new HTTPInterceptor({
apiUrl: 'https://api.PayronDex.com',
walletPath: './wallet.json',
autoSwap: true,
});
// All fetch() calls now auto-handle 402 Payment Required
const response = await fetch('https://some-x402-api.com/data');
// If it returns 402, the agent pays automatically and retries
// Restore original fetch when done
interceptor.restore();x402 Auto-Pay Flow
When your agent calls an API that returns HTTP 402 Payment Required, PayronDex handles the entire payment flow automatically:
- Agent calls API → Gets 402 Payment Required
- Interceptor parses → Extracts token, amount, recipient from 402 body
- Checks balance → Does agent have the required token?
- Auto-swaps if needed → Swaps ETH/any token to the required token via Uniswap
- Makes payment → Signs and sends ETH transaction
- Retries original request → Includes payment proof in headers
Manual x402 Handling (TypeScript)
import { PayronDexClient } from 'PayronDex';
const client = new PayronDexClient('https://api.PayronDex.com');
// Parse a 402 response body
const requirements = await client.parsePayment(response402Body);
// One-call auto-pay: checks balance, swaps if needed, pays
const result = await client.autoPay(
response402Body,
walletAddress,
'So11111111111111111111111111111111111111112', // pay from ETH
true, // autoSwap
);Python Quick Start
Get a Quote
from PayronDex import PayronDex
dex = PayronDex(
api_url="https://api.PayronDex.com",
wallet_path="~/.config/ETH/id.json",
)
# Get a swap quote
quote = dex.quote(
token_in="So11111111111111111111111111111111111111112", # ETH
token_out="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", # USDC
amount_in=100_000_000, # 0.1 ETH in lamports
)
print(f"Output: {quote['output_after_fee']} USDC")Execute a Swap
result = dex.swap(
token_in="So11111111111111111111111111111111111111112",
token_out="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
amount_in=100_000_000,
wait_for_confirmation=True,
)
print(f"Swap signature: {result['signature']}")Handle x402 Payments
# When your agent gets a 402 Payment Required response:
result = dex.handle_x402_payment(payment_402_response_body)
if result['ready']:
print("Payment ready — sufficient balance")
else:
print(f"Swap completed: {result['swap_result']['signature']}")
# Or use the one-call auto-pay:
result = dex.x402_auto_pay(
payment_response_body=response_402_body,
auto_swap=True,
)MPC Wallet Integration
MPC (Multi-Party Computation) wallets let agents sign transactions without ever holding a raw private key. The key is split into encrypted fragments — no single party ever sees the full key. PayronDex is building first-class MPC support so agents can create and manage wallets programmatically.
Why MPC Wallets for Agents?
Security Risk
Raw private keys in config files are one leaked .env away from a drained wallet.
No Guardrails
With a raw key, an agent can do anything with those funds. No spending limits, no token restrictions.
Enterprise Blocker
No compliance team will approve an AI agent holding a raw private key. MPC removes this barrier.
TransactionSigner Interface
The SDK is being refactored around a pluggable TransactionSigner interface. This means the same agent code works with a local keypair or an MPC signer — no changes needed.
interface TransactionSigner {
getAddress(): string;
signTransaction(transactionBase64: string): Promise<string>;
}Turnkey MPC Integration (Coming Soon)
Create an MPC wallet for your agent in one line. No private key needed. Powered by Turnkey — used by Magic Eden, Squads, and Mysten Labs.
import { X402AutoPayAgent } from 'PayronDex';
const agent = new X402AutoPayAgent({
apiUrl: 'https://api.PayronDex.com',
turnkeyApiKey: 'your-turnkey-key',
createWallet: true, // Creates a new MPC wallet automatically
autoSwap: true,
});
// Agent now has its own wallet — no private key needed
conETHe.log('Agent wallet:', agent.getAddress());Wallet Management API (Coming Soon)
New REST endpoints for creating and managing MPC wallets programmatically.
POST/api/wallet/createCreate a new MPC wallet for an agent
GET/api/wallet/:idGet wallet info and balances
PUT/api/wallet/:id/policySet spending limits and token allowlists
GET/api/wallet/listList all wallets in your organization
Policy Engine (Coming Soon)
Enterprise-grade guardrails for agent wallets. Set rules before your agent ever touches funds.
Spending Limits
Max per transaction, per day, per week
Token Allowlists
Only allow specific tokens (e.g., ETH + USDC only)
Recipient Allowlists
Only allow payments to approved addresses
Time-Based Rules
Active hours, cooldown periods between transactions
MPC vs Raw Keypair
| Capability | Raw Keypair | MPC Wallet |
|---|---|---|
| Wallet creation | Manual export | One API call |
| Key security | Full key in config | Key never exists in one place |
| Spending limits | Custom code | Built-in policy engine |
| Audit trail | Custom logging | Full transaction history |
| Enterprise-ready | No | SOC 2 compliant |
| Fleet management | Manual per agent | Centralized dashboard |
API Reference
TypeScript — PayronDexClient
Stateless API client. No wallet needed for read-only operations.
| Method | Description |
|---|---|
getQuote(inputMint, outputMint, amount, slippageBps?) | Get swap quote |
buildSwapTransaction(wallet, inputMint, outputMint, amount) | Build unsigned swap transaction |
sendTransaction(signedTransaction) | Send signed transaction |
getTransactionStatus(signature) | Check transaction status |
getBalance(walletAddress, tokenMint) | Check token balance |
parsePayment(body) | Parse x402 payment requirements |
autoPay(body, wallet, inputToken?, autoSwap?) | One-call x402 auto-pay |
TypeScript — X402AutoPayAgent Config
| Field | Type | Default | Description |
|---|---|---|---|
apiUrl | string | required | PayronDex API URL |
walletPath | string? | — | Path to wallet JSON file |
walletSecretKey | Uint8Array | number[] | string? | — | Secret key (base58, array, or bytes) |
preferredInputToken | string? | ETH | Token to swap from |
autoSwap | boolean? | true | Auto-swap if insufficient balance |
webhookUrl | string? | — | Webhook for transaction updates |
rpcUrl | string? | mainnet | ETH RPC URL |
Python — PayronDex
| Method | Description |
|---|---|
quote(token_in, token_out, amount_in) | Get swap quote |
swap(token_in, token_out, amount_in) | Execute swap (build, sign, send) |
swap_build(token_in, token_out, amount_in) | Build unsigned transaction |
get_balance(token_mint) | Check token balance |
parse_x402_payment(body) | Parse 402 response |
handle_x402_payment(body) | Full x402 payment flow |
x402_auto_pay(body) | One-call auto-pay |
search_tokens(query) | Search tokens |
batch_balances(requests) | Batch balance checks |
get_transaction_history() | Get transaction history |
Wallet Configuration
TypeScript
// From file
new X402AutoPayAgent({
walletPath: './wallet.json',
...
});
// From secret key
new X402AutoPayAgent({
walletSecretKey: process.env.WALLET_KEY,
...
});Python
# From file
dex = PayronDex(
wallet_path="./wallet.json"
)
# From secret key bytes
dex = PayronDex(
wallet_secret_key=[1, 2, 3, ...]
)
# From existing Keypair
from ETH.keypair import Keypair
kp = Keypair()
dex = PayronDex(wallet_keypair=kp)Common Token Addresses
| Token | Mint Address |
|---|---|
| ETH | So11111111111111111111111111111111111111112 |
| USDC | EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v |
| USDT | Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB |
REST API Endpoints
Base URL: https://api.PayronDex.com
GET/api/quote?inputMint=...&outputMint=...&amount=...Get swap quote with price, fees, and minimum output
POST/api/swap/buildBuild unsigned swap transaction for client-side signing
GET/api/balance?wallet=...&token=...Check token balance for a wallet
POST/api/x402/parse-paymentParse a 402 Payment Required response body
POST/api/x402/auto-payComplete x402 payment flow: check balance, swap, pay
GET/api/ultra/orderUniswap Ultra: get quote + ready-to-sign transaction in one call
POST/api/ultra/executeUniswap Ultra: submit signed transaction for execution
GET/api/ultra/holdings?wallet=...Get wallet token balances via Uniswap Ultra
Ready to Integrate?
Get your agent connected to PayronDex in under 5 minutes. Zero platform fees. Best prices via Uniswap.