Skip to main content

Installation

npm install @agentwallex/sdk

Client Initialization

import { AgentWallex } from "@agentwallex/sdk";

const aw = new AgentWallex({
  apiKey: process.env.AGENTWALLEX_API_KEY!,
  environment: "sandbox",  // "sandbox" | "production"
  baseUrl: undefined,       // Custom endpoint (optional)
  timeout: 30000,           // Request timeout in ms (default: 30000)
});
ParameterTypeDefaultDescription
apiKeystringRequiredYour API key (awx_...)
environment"sandbox" | "production""sandbox"Target environment
baseUrlstringCustom base URL (overrides environment)
timeoutnumber30000Request timeout in milliseconds

Agents

aw.agents.create(params)

Create a new agent with an MPC-secured wallet.
const agent = await aw.agents.create({
  name: "my-agent",
  chain: "eip155:8453",
  policies: {
    maxTransactionAmount: "100",
    dailyLimit: "1000",
    allowedAddresses: ["0x..."],
    allowedTokens: ["USDC"],
    requireHumanApproval: false,
  },
  metadata: { team: "growth" },
});
Returns:
FieldTypeDescription
idstringUnique agent identifier
namestringAgent display name
wallet.addressstringOn-chain wallet address
wallet.chainstringCAIP-2 chain identifier
statusstring"active" or "frozen"
createdAtstringISO 8601 timestamp

aw.agents.get(agentId)

Retrieve an agent by ID.
const agent = await aw.agents.get("agent_abc123");

aw.agents.list(params?)

List all agents for your account.
const { agents, pagination } = await aw.agents.list({
  limit: 20,
  offset: 0,
  status: "active",
});

aw.agents.freeze(agentId)

Immediately freeze an agent’s wallet, preventing all transactions.
await aw.agents.freeze("agent_abc123");

aw.agents.unfreeze(agentId)

Re-enable an agent’s wallet after a freeze (subject to 10-minute cool-down).
await aw.agents.unfreeze("agent_abc123");

Payments

aw.payments.send(params)

Send a direct on-chain payment.
const tx = await aw.payments.send({
  agentId: "agent_abc123",
  to: "0xRecipientAddress",
  amount: "50.00",
  token: "USDC",
  memo: "Payment for API access",
});
Returns:
FieldTypeDescription
idstringTransaction ID
hashstringOn-chain transaction hash
statusstring"pending", "confirmed", "failed"
amountstringAmount sent
tokenstringToken symbol
feestringNetwork gas fee paid

aw.payments.get(transactionId)

Get transaction details and status.
const tx = await aw.payments.get("tx_xyz789");

aw.payments.list(params)

List transactions for an agent.
const { transactions } = await aw.payments.list({
  agentId: "agent_abc123",
  limit: 50,
  status: "confirmed",
});

x402 Micropayments

aw.x402.createSession(params)

Create an x402 payment session with a spending budget.
const session = await aw.x402.createSession({
  agentId: "agent_abc123",
  budgetLimit: "100.00",
  chain: "eip155:84532",
  ttlSeconds: 3600,
  allowedUrls: ["https://paid-api.example.com/v1/data"],
});

aw.x402.check(params)

Check whether a target URL supports x402 payment negotiation.
const info = await aw.x402.check({
  url: "https://paid-api.example.com/v1/data",
});

aw.x402.pay(params)

Negotiate and complete one x402 payment.
const result = await aw.x402.pay({
  agentId: "agent_abc123",
  targetUrl: "https://paid-api.example.com/v1/data",
  sessionId: session.id,     // optional
  chain: "eip155:84532",     // optional
});

aw.x402.sessionPay(sessionId, params)

Pay using an existing session budget.
await aw.x402.sessionPay(session.id, {
  targetUrl: "https://paid-api.example.com/v1/data",
});

aw.x402.httpInterceptor(params)

Create an HTTP fetch wrapper that automatically handles x402 v2 challenges:
const fetchWithPayment = aw.x402.httpInterceptor({
  agentId: "agent_abc123",
  chain: "eip155:84532",
});

// Automatically handles 402 -> pay -> retry flow
const response = await fetchWithPayment("https://paid-api.example.com/v1/data");
const data = await response.json();
The interceptor:
  1. Reads the PAYMENT-REQUIRED header from a 402 response
  2. Submits payment via AgentWallex
  3. Retries the request with the PAYMENT-SIGNATURE header

Policies

aw.policies.update(agentId, policies)

Update an agent’s spending policies.
await aw.policies.update("agent_abc123", {
  maxTransactionAmount: "200",
  dailyLimit: "2000",
  allowedAddresses: ["0xAddr1", "0xAddr2"],
  velocityLimit: { maxCount: 100, windowSeconds: 3600 },
});

aw.policies.get(agentId)

Get current policies for an agent.
const policies = await aw.policies.get("agent_abc123");

aw.policies.applyTemplate(agentId, templateName)

Apply a policy template to an agent.
await aw.policies.applyTemplate("agent_abc123", "conservative");

aw.policies.createTemplate(name, rules)

Create a reusable policy template.
await aw.policies.createTemplate("my-template", {
  maxTransactionAmount: "200",
  dailyLimit: "2000",
  allowedTokens: ["USDC"],
  velocityLimit: { maxCount: 50, windowSeconds: 3600 },
});

Webhooks

aw.webhooks.create(params)

Register a webhook endpoint.
const webhook = await aw.webhooks.create({
  url: "https://your-app.com/webhooks/agentwallex",
  events: [
    "payment.completed",
    "payment.failed",
    "agent.frozen",
    "policy.violated",
  ],
  secret: "whsec_your_signing_secret",
});

Error Handling

The SDK provides typed error classes:
import {
  AgentWallexError,
  PolicyViolationError,
} from "@agentwallex/sdk";

try {
  await aw.payments.send({ ... });
} catch (error) {
  if (error instanceof PolicyViolationError) {
    console.log(`Policy violated: ${error.rule}`);
    console.log(`Details: ${error.message}`);
  } else if (error instanceof AgentWallexError) {
    console.log(`API error: ${error.code} - ${error.message}`);
  }
}
Error ClassWhen Thrown
AgentWallexErrorBase class for all API errors
PolicyViolationErrorTransaction blocked by policy engine
AuthenticationErrorInvalid or missing API key
NotFoundErrorResource does not exist
RateLimitErrorRate limit exceeded

TypeScript Types

All types are exported from the package:
import type {
  Agent,
  Payment,
  Transaction,
  Policy,
  X402Session,
  WebhookEvent,
} from "@agentwallex/sdk";