Cookbook#
Task-oriented recipes for common TetraFi integration patterns. Each recipe is self-contained - copy the code, swap in your credentials, and run.
The most common flow: create an RFQ, wait for solver quotes, and accept the best price.
After accepting a quote, poll settlements.get() until the state reaches a terminal value.
Prefer WebSocket events over polling for production - recipe #5 shows how.
Verify your address has a valid ComplianceRegistry attestation before submitting orders.
Query which cross-chain routes are available with solver coverage.
1curl -s https://api.tetrafi.io/api/v1/corridors | jq '.corridors[] | {id, solverCount, oracle}'Response shape - each corridor includes originChainId, destinationChainId, token pair, solver count, supported lock types, and min/max notional. See API Reference for the full schema.
Real-time updates without polling - connect once, subscribe to channels.
The API returns 429 with a Retry-After header. Respect it.
Receive server-to-server callbacks instead of polling or holding a WebSocket.
1curl -X POST https://api.tetrafi.io/api/v1/webhooks \2 -H "Authorization: Bearer $TETRAFI_API_KEY" \3 -H "Content-Type: application/json" \4 -d '{5 "url": "https://your-server.com/webhooks/tetrafi",6 "events": ["order.created", "order.settled", "compliance.event"],7 "secret": "whsec_your_secret"8 }'Verify signatures with HMAC-SHA256 - see Events & Webhooks for the verification algorithm.
Every compliance-gated settlement generates a hash-chained audit record.
End-to-end cross-chain settlement with corridor specification.
Sandbox uses testnet tokens and simulated solvers. Production uses real assets.
Never hardcode production keys. Always use environment variables (process.env.TETRAFI_API_KEY / os.environ["TETRAFI_API_KEY"]).