Skip to Content
KryptWarden Developers
Agent SDK

Errors

KryptWardenPaymentError, its codes, and what to do about each.

When the policy stops a payment, kw.fetch() throws a KryptWardenPaymentError. Network failures that have nothing to do with payment behave like normal fetch.

class KryptWardenPaymentError extends Error {
  readonly code: KryptWardenErrorCode;
  readonly requestId: string; // hex, unique per payment attempt
  readonly agentPublicKey: string;
  readonly walletAddress: string;
  readonly seller?: string;
  readonly amountStroops?: string;
  readonly amountUsdc?: string;
  readonly holdId?: number;
  readonly txHash?: string;
  readonly contractErrorCode?: number; // see Contract errors
}

err.message starts with the code in brackets, for example [REJECTED_BUDGET] Payment of 2.00 USDC exceeds remaining daily budget (1.55 USDC).

Codes

CodeWhenWhat to do
REJECTED_BUDGETThe payment would take today's spend plus open holds over the daily budgetWait for the next UTC day, or ask the owner to raise the budget
REJECTED_SELLERThe payTo address isn't on the agent's allow-listAsk the owner to add the seller, or use another one
HOLD_DENIEDThe owner denied the holdDon't retry automatically
HOLD_EXPIREDNobody decided before the hold timeout, or maxHoldWaitMs ran outRetry later, or notify the owner sooner with onHoldCreated
AGENT_PAUSEDThe owner paused this agentStop paid work until it's resumed
AGENT_REVOKEDThe key isn't registered on this wallet, or was revokedCheck walletAddress and the key; register again if needed
AGENT_EXPIREDThe key's expires_at has passedThe owner must update the policy
WALLET_PAUSEDThe owner hit the wallet-wide kill switchStop paid work
BAIT_AND_SWITCH_DETECTEDAfter approval, the seller's new challenge asked for a different amount, recipient or assetTreat the seller as untrusted
FACILITATOR_ERRORRelayer or facilitator failure, a malformed 402, or an unsupported assetSafe to retry with backoff

Which refusals are recorded

For REJECTED_BUDGET, REJECTED_SELLER and the agent-state codes, the SDK asks the relayer to record a PaymentRejected event on the wallet before throwing. The owner sees the attempt in the Spend Ledger with its reason. Recording is best-effort: if the relayer is down, the payment is still refused.

Contract error mapping

When the contract itself refuses (for example a policy changed between the SDK's check and settlement), the SDK maps the contract error number to a code:

Contract errorSDK code
BudgetExceeded (115)REJECTED_BUDGET
SellerNotAllowed (114)REJECTED_SELLER
HoldExpired (120)HOLD_EXPIRED
HoldNotApproved (118)HOLD_DENIED
AgentExpired (108)AGENT_EXPIRED
AgentNotActive (107), AgentNotFound (106)AGENT_REVOKED
WalletPaused (109), OpenZeppelin pause (1000)WALLET_PAUSED
anything elseFACILITATOR_ERROR

The original number is kept in err.contractErrorCode. All numbers are listed in Contract errors.

On this page