SDK
TypeScript SDK
The primary ClawdGo SDK. Full type coverage, tree-shakeable, no heavyweight dependencies.
Installation
bash
npm install @clawdgo/sdk
Initialize the client
typescript
import { ClawdGo } from "@clawdgo/sdk";
const client = new ClawdGo({
apiKey: process.env.CLAWDGO_API_KEY,
});
Accounts
typescript
// Provision a new agent account
const account = await client.accounts.create({
name: "research-agent-prod",
});
console.log(account.account_id); // acct_01j8k4x9p2qrst7yz
console.log(account.solana_address); // 9xTz4KqR8...
// Get balance
const { balance_usdc } = await client.accounts.getBalance("acct_01j8k4x9p2qrst7yz");
// List accounts
const { data } = await client.accounts.list({ limit: 50 });
Transfers
typescript
const transfer = await client.transfers.create({
from: "acct_01j8k4x9p2qrst7yz",
to: "9xTz4KqR8mYvPn3SdFgHj6WbCeAuLo1XkQi5NtZpMwV",
amount: "120.00",
memo: "Invoice #1042",
idempotency_key: "inv-1042-2024-01-15",
});
console.log(transfer.status); // "settled"
console.log(transfer.tx_signature); // Solana signature
Policy
typescript
// Update policy (operator key required)
await client.policy.update("acct_01j8k4x9p2qrst7yz", {
max_single_transfer: 500,
max_daily_spend: 2000,
require_memo: true,
paused: false,
});
// Emergency pause
await client.policy.pause("acct_01j8k4x9p2qrst7yz");
Error handling
typescript
import { ClawdGoError, PolicyViolationError } from "@clawdgo/sdk";
try {
await client.transfers.create({ ... });
} catch (err) {
if (err instanceof PolicyViolationError) {
console.error("Blocked by policy:", err.message);
// Handle: escalate to operator, log, etc.
} else if (err instanceof ClawdGoError) {
console.error("API error:", err.code, err.message);
} else {
throw err;
}
}
TypeScript types
All SDK methods are fully typed. Key exported types:
| Type | Description |
|---|---|
Account | Full account object with balance and policy |
Transfer | Settled or rejected transfer record |
SpendingPolicy | Policy configuration object |
WebhookPayload<T> | Generic webhook envelope, parameterized by event type |
ClawdGoError | Base error class with code, message, status |