Build
HTTP API.
Every desk is one POST; every decision is a signed memo you can fetch and verify; no API key is needed. The first 5 runs a day per IP address are free; after that a run costs $0.05 in test USDC over x402.
Routes
| Method and path | What it does |
|---|---|
POST /api/preflight | runs a desk: mode is trade, listing, holdings or settlement |
POST /api/resolve | resolves a prediction market |
GET /api/memo/:id | a stored desk memo with its sha256, message, signature and signer |
GET /api/memos?limit=n | the latest desk decisions (up to 50) and the signer |
GET /api/resolution/:id, GET /api/resolutions | a stored resolution with its Solana anchor; the latest resolutions (?current=1 keeps only the latest run of each market) |
POST /api/memo/verify | {memo, signature}: recomputes the digest and recovers the signer; free |
GET /api/signal/:hash | looks up a Telegraph signal hash on the node |
GET /api/stats | live counters, the free allowance left for you, the price, and the node's ledger for Shield's escrow |
POST /api/check, GET /api/report/:id, GET /api/recent, GET /api/verify/:txHash | the Season I pre-sign check behind /app |
GET /healthz | {ok: true} |
Examples
# a trading agent: may I buy $1,000 of WETH through the Uniswap V3 USDC/WETH pool?
curl -s https://truvian.xyz/api/preflight -H 'content-type: application/json' -d '{
"mode": "trade", "chain": "ethereum",
"token": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"pool": "0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640",
"tradeUsd": 1000
}' | jq '{decision: .memo.decision, rule: .memo.decisionRule, cost: .memo.cost, url}'
# a custodian: may I pay 1 rUSD to this counterparty on Solana devnet?
curl -s https://truvian.xyz/api/preflight -H 'content-type: application/json' -d '{
"mode": "settlement", "network": "solana-devnet", "mint": "RUSD", "amount": "1",
"recipient": "Afb8MYs9G63oHAPkZiK6cb5JKzuWy9is3pHc6Zj5voYZ",
"counterparty": "Coinbase Global, Inc.", "jurisdiction": "US-DE", "execute": true
}' | jq '{decision: .memo.decision, sent: .memo.settlement.execution.reason}'
# a market: what really happened?
curl -s https://truvian.xyz/api/resolve -H 'content-type: application/json' \
-d '{"source": "polymarket", "market": "253591"}' | jq '{decision: .memo.decision, outcome: .memo.outcome, anchor}'
A successful run answers {type: "memo", id, memo, sha256, message, signature, signer, url}. Invalid input is 400 INVALID_INPUT with a message; a chain that does not answer is 503 and nothing is bought.
Streaming
Add ?stream=1 (or accept: application/x-ndjson) to watch a decision assemble as newline-delimited JSON:
| Event | Carries |
|---|---|
start | the normalized input |
chain / holdings / solana | Shield's own reads: token facts, each holding, or the Solana mint, its restrictions and the payer's balance |
market | resolution only: the market as its venue states it |
plan | the facts to buy and the escrow balance |
purchase / answer | one per answer, with miner, cost, latency, receipt and signal |
execution | settlement only: whether the payment was sent, and its read-back |
memo | the signed memo |
payment | on a paid run: whether your payment settled, and its transaction |
done | your free runs left today |
Paying with x402
Past the free runs, a desk answers 402 with a price instead of running:
{"x402Version": 1,
"error": "... Pay $0.05 in USDC to run this check now.",
"accepts": [{"scheme": "exact", "network": "base-sepolia", "maxAmountRequired": "50000",
"payTo": "0xCd0a2370F2dC12c1802707B7d9aB3fec891E3c02",
"asset": "0x036CbD53842c5426634e7929541eC2318f3dCF7e", "maxTimeoutSeconds": 300,
"extra": {"name": "USDC", "version": "2"}}]}
Sign an EIP-3009 TransferWithAuthorization for that amount and send the same request again with X-PAYMENT: base64({x402Version, scheme, network, payload: {signature, authorization}}). Shield verifies it with the facilitator before running and settles it only after the run succeeds; the caller pays no gas. On the website this is automatic: pay.js shows the price and wallet.js asks the visitor's browser wallet for the signature. A malformed header counts as no payment; a well-formed one with a bad signature is refused with 402 and nothing runs.
Verifying a memo
A memo's digest is SHA-256 over its canonical JSON (keys sorted, no spaces; canonicalJson in src/shield/memo.ts). The signed message is Truvian Shield memo sha256:<digest> under EIP-191. POST /api/memo/verify answers {sha256, message, recoveredSigner, signedByThisShield, shieldSigner}; any EIP-191 library recovers the same signer offline. Change one field and it fails.
Limits
- 5 free runs per IP address a day, reset at 00:00 UTC, and at most 3 a minute (
SHIELD_FREE_CHECKS_PER_IP,SHIELD_BURST_PER_MIN). - At most 300 free runs and $5 of Telegraph spend a day across everyone (
SHIELD_DAILY_CHECK_CAP,SHIELD_DAILY_SPEND_USD). - $0.10 of Telegraph answers per decision (
SHIELD_PREFLIGHT_BUDGET_USD); a plan over it buys nothing. - A settlement sends at most 1 token, on devnet, from Shield's wallet.
