Skip to Content
KryptWarden Developers
Agent SDK

API reference

Every function and type exported by @kryptwarden/sdk.

createKryptWarden(config)

function createKryptWarden(config: KryptWardenConfig): KryptWardenClient;

Creates a client for one agent on one wallet. See Configuration.

KryptWardenClient

interface KryptWardenClient {
  fetch(input: string | URL | Request, init?: RequestInit): Promise<Response>;
  getSummary(): Promise<OnChainAgentSummary>;
}

kw.fetch(input, init?)

Same signature as fetch. Non-402 responses are returned unchanged. On 402 it pays within policy and returns the paid response, or throws a KryptWardenPaymentError.

The settlement transaction hash is returned by the seller in the PAYMENT-RESPONSE header. Read it with extractSettlementTxHash(res).

kw.getSummary()

Reads this agent's live state from the wallet contract.

interface OnChainAgentSummary {
  agentKeyHex: string;
  agentPublicKey: string; // G…
  status: "Active" | "Paused" | "Revoked";
  isExpired: boolean;
  policy: OnChainPolicy;
  policyVersion: number;
  spentTodayStroops: bigint;
  reservedHoldsStroops: bigint;
  remainingBudgetStroops: bigint;
  activeHoldCount: number;
}

interface OnChainPolicy {
  dailyBudgetStroops: bigint;
  autoApproveLimitStroops: bigint;
  allowedSellers: string[];
  expiresAt: number; // unix seconds
  approvalTimeoutSecs: number;
}

HoldLifecycleNotification

Passed to onHoldCreated.

interface HoldLifecycleNotification {
  holdId: number;
  seller: string;
  amountStroops: string;
  amountUsdc: string;
  expiresAt: number; // unix seconds
  txHash?: string; // the request_hold transaction
}

Read helpers

Read-only contract calls through simulation. They need no keys and cost nothing.

readWalletPaused(rpcUrl, networkPassphrase, walletAddress): Promise<boolean>;
readWalletOwner(rpcUrl, networkPassphrase, walletAddress): Promise<string | null>;
readWalletUsdcBalance(rpcUrl, networkPassphrase, usdcSacAddress, walletAddress): Promise<bigint>;
readUnreservedBalance(rpcUrl, networkPassphrase, walletAddress): Promise<bigint>;
readAgentKeys(rpcUrl, networkPassphrase, walletAddress): Promise<string[]>;
readAgentSummary(rpcUrl, networkPassphrase, walletAddress, agentPublicKeyOrHex): Promise<OnChainAgentSummary>;
readHold(rpcUrl, networkPassphrase, walletAddress, holdId): Promise<OnChainHoldRecord>;
import { readUnreservedBalance, formatStroopsToUsdc } from "@kryptwarden/sdk";
import { Networks } from "@stellar/stellar-sdk";

const free = await readUnreservedBalance(
  "https://soroban-testnet.stellar.org",
  Networks.TESTNET,
  "CBRSOOZPMVB3SX6LPRG6ESCRBOPP6G4OZHVIQUNCVRQPNMCUE5BB4NVO",
);
console.log(formatStroopsToUsdc(free), "USDC unreserved");
interface OnChainHoldRecord {
  id: number;
  agentKeyHex: string;
  agentPublicKey: string;
  seller: string;
  amountStroops: bigint;
  status: "Pending" | "Approved" | "Denied" | "Consumed" | "Expired" | "Cancelled";
  createdAt: number;
  expiresAt: number;
  requestIdHex: string;
  policyVersion: number;
}

Utilities

ExportWhat it does
formatStroopsToUsdc(value)30000000n → "3.00"
resolveRelayerUrl(network, explicit?)The relayer the client will use
DEFAULT_TESTNET_RELAYER_URL"https://pay.kryptwarden.xyz"
extractSettlementTxHash(res)Settlement transaction hash from a paid response, if present
mapContractErrorToSdkCode(code)Contract error number → SDK error code
extractContractErrorCode(message)Finds Error(Contract, #N) in an RPC error string

Low-level building blocks

For building your own client or relayer. Most agents never need these.

ExportPurpose
KryptWardenStellarClientSchemex402 client scheme that signs the wallet's custom-account auth entry
encodeKwSignatureScVal, decodeKwSignatureFromEnvelopeXdrEncode or decode the KwSignature the wallet expects
buildSignedAgentIntent, verifySignedAgentIntentOffChainSign or verify KW_HOLD1 / KW_REJ1 intents
encodeHoldRequestInputScVal, encodeRejectionInputScValTurn a signed intent into the contract's input struct
KwContractErrorCodeEnum of the contract errors

On this page