Lifecycle
- A developer registers an agent for the
wallet:read,wallet:spend, the merchant action scope (for exampletravel:book), and optionalwallet:reload:requestscopes. - The principal authorizes those scopes through OAuth Agent Grants.
- The application creates a short-lived principal session.
- The principal creates and funds one or more wallets.
- The principal assigns wallets with transaction, rolling, recipient, resource, scope, validity, and optional shared budget-group policy.
- The DPoP-authenticated agent reserves value before presenting a payment.
- A layered policy may deny, allow, or require an exact principal approval.
- The resource server verifies and settles the one-time authorization.
- The principal reviews decisions, approves payments or reloads, or blocks spending.
Wallet states
Assignments independently use
active, blocked, or revoked. Revocation is
terminal. A principal can also set allWalletsBlocked for one agent, scoped to
that principal and developer.
Balance accounting
Balances areNUMERIC(78,0) atomic-unit integers:
Assignment and layered policy evaluation
An authorization succeeds only if all of these remain true while the wallet row is locked:- wallet, assignment, grant, and OAuth access token are active;
- the agent is not globally blocked by the principal;
- assignment validity dates include the current time;
- asset and network match the wallet;
- recipient, HTTPS resource origin, and scope are explicitly allowed or the corresponding allow-any choice was made;
- the payment scope is present in the human-approved OAuth grant;
- amount does not exceed the per-transaction cap;
- reserved plus settled value in the rolling window, plus the new amount, does not exceed the cumulative cap;
- enough available value exists.
budgetGroup, principal, or
developer. They can deny, always require approval, or enforce amount and count
limits over per-authorization, rolling, day, week, month, or lifetime windows.
Filters cover recipient, resource origin, action scope, asset, network,
merchant ID, purpose, project ID, cost center, and verified merchant state.
All matching layers compose; a narrow policy cannot override a broader deny or
increase a stricter limit. Reserved and settled amounts both count toward
usage. Cross-wallet and cross-agent policy evaluation uses a shared advisory
lock, while balance movement uses the wallet row lock.
Concurrent requests serialize on the wallet row. The database update also
requires available_amount >= amount, so a race cannot overdraw the wallet even
if callers arrive together.
Exact payment approval
A policy can returnapproval_required instead of creating a reservation. The
approval is durable, short-lived, and bound to the exact agent, wallet,
assignment, amount, asset, network, recipient, resource, scope, merchant,
purpose, project, cost center, matched policies, and idempotency key. The
principal approves or rejects it through the dashboard or principal-session
API.
An approved retry must repeat the original terms and is consumed when the
reservation succeeds. It cannot be reused for a different transaction. The
authorization JWT also binds the semantic context, so changing it at x402
verification or settlement fails closed.
Reload separation of duties
An agent may ask for a reload only when available value reaches the configured low-balance threshold. It cannot approve or fund the request. The principal can:- approve, then fund;
- reject;
- leave the request pending;
- fund directly without an agent request in sandbox mode.
Custody boundary
sandbox_ledger is the internal-ledger implementation. It is suitable for
local development, deterministic integration tests, and off-chain prepaid
accounting where the Grantex ledger is explicitly the system of record.
external with operator-configured base_usdc supports native Base USDC
EIP-3009 payments. It verifies finalized funding receipts and settlement evidence
and persists signatures with balance reservations. See Base USDC custody
for provisioning, SDK availability and the in-process signing-key risk.
Other or unconfigured providers fail with CUSTODY_ADAPTER_UNAVAILABLE.
Arbitrary provider references never become spendable value.
For Base, blocking prevents new signatures but does not cancel already signed
payments. Those reservations remain held and count against limits until
finalized settlement or unused expiry, including across server restarts and RPC
outages. Reconciliation never accepts caller-invented settlement evidence.
API families
Principal-session endpoints are under/v1/principal/prepaid-wallets* and cover
wallets, assignments, direct reloads, reload decisions, activity, and release or
block actions. Principal policies and exact approvals use
/v1/principal/prepaid-wallet-spend-policies* and
/v1/principal/prepaid-wallet-payment-approvals*. Developer-level policies use
/v1/prepaid-wallet-spend-policies* under API-key authentication. DPoP agent
endpoints are under /v1/prepaid-wallets* and cover listing, payment
authorization, and reload requests. The official x402 v2
facilitator endpoints are /v1/x402/supported, /v1/x402/verify, and
/v1/x402/settle.
See the x402 integration guide for code and failure
handling and Agent Wallet Governance for the
Grantex, issuer, runtime, principal, and merchant boundaries. Self-hosting
operators must also complete Prepaid Wallet Production
Readiness for public routing, migration,
notification, merchant-recovery, custody, and external-review dependencies.