VITE_API_URL to this backend.
Base URL
Authentication
Guarded routes use a SIWX (Sign-In With X) bearer flow. Wallets sign a CAIP-122 multi-line message via BIP-322 once per session, exchange the signature for a short-lived bearer token, then attach that token to subsequent requests. The legacyx-user-address header is still accepted during migration, but the bearer token is preferred. New integrations should use the bearer flow.
Flow
Request a nonce
The frontend calls
POST /api/auth/nonce with the wallet address. The backend returns a single-use nonce and the exact CAIP-122 message the wallet must sign.Sign and verify
The wallet signs the message using BIP-322 (chipnet or mainnet). The frontend posts the signature to
POST /api/auth/verify and receives a bearer token. Tokens are HMAC-SHA256 signed and expire 30 minutes after issue.Nonce
Verify
| Field | Type | Notes |
|---|---|---|
token | string | HMAC-SHA256 bearer, 30-minute TTL |
address | string | CashAddr the token is bound to |
expiresAt | string (ISO 8601) | Token expiry |
Authed request
Frontend SDK helper
The frontend shipsauthFetch in frontend/src/utils/auth.ts. It wraps fetch and handles the SIWX round-trip transparently:
- Caches the bearer in
sessionStoragekeyed by wallet address. - Reuses the cached token until it expires.
- On
401, drops the cached token, repeats nonce + verify, and retries the original request once.
/api/streams/create). Follow each endpoint’s request spec.
WalletConnect Transactions
Most on-chain build endpoints return awcTransaction object rather than broadcasting directly. The frontend passes this to the connected wallet (Paytaca, Selene) via WalletConnect v2 using bch_signTransaction. After the wallet signs and broadcasts, the frontend calls the corresponding confirm-* endpoint with the resulting txHash.
Common Response Shape
Many endpoints include"success": true at the top level:
success wrapper. Errors return a non-2xx status with "error" and optionally "message":
Lifecycle Pattern
Most on-chain actions follow this two-step lifecycle:Build
Call a build endpoint that returns a wallet payload (for example
GET /api/streams/:id/funding-info, POST /api/streams/:id/claim, or POST /api/airdrops/:id/pause)./api/streams/create, /api/payments/create, /api/airdrops/create) return deployment metadata first, then require a separate funding build call.
Status Values
Most stream/distribution resources share this status lifecycle:| Status | Meaning |
|---|---|
PENDING | Contract deployed, awaiting funding |
ACTIVE | Funded and live on-chain |
PAUSED | Temporarily halted by authority |
CANCELLED | Terminated early, funds returned |
COMPLETED | All obligations fulfilled |
pending, approved, executed, rejected for treasury proposals).
