This guide covers the ftUSD preview endpoints for simulating operations and session management endpoints for session key delegation.
Production: https://api.flyingtulip.com (or your configured API URL)
These endpoints allow you to preview mint/redeem/stake/unstake operations without requiring the user's wallet to be connected to a specific chain. Useful for multi-chain UIs.
Preview how much ftUSD will be minted for a given collateral amount.
GET /ftusd/preview/mint?chainId={chainId}&collateralToken={tokenAddress}&amount={amount}
Parameters:
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| chainId | int | No | 1 | Chain ID |
| collateralToken | string | Yes | - | Collateral token address (0x...) |
| amount | string | Yes | - | Collateral amount in wei (base-10 integer) |
Response:
{
"success": true,
"chain_id": 1,
"input": "1000000000",
"output": "1000000000000000000"
}Preview how much collateral will be received for a given ftUSD amount.
GET /ftusd/preview/redeem?chainId={chainId}&collateralToken={tokenAddress}&amount={amount}
Parameters:
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| chainId | int | No | 1 | Chain ID |
| collateralToken | string | Yes | - | Collateral token address |
| amount | string | Yes | - | ftUSD amount to redeem in wei (base-10 integer) |
Response:
{
"success": true,
"chain_id": 1,
"input": "1000000000000000000",
"output": "1000000000"
}Preview how many sftUSD shares will be received for staking ftUSD.
GET /ftusd/preview/stake?chainId={chainId}&amount={amount}
Parameters:
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| chainId | int | No | 1 | Chain ID |
| amount | string | Yes | - | ftUSD amount to stake in wei (base-10 integer) |
Response:
{
"success": true,
"chain_id": 1,
"input": "1000000000000000000",
"output": "950000000000000000"
}Preview how much ftUSD will be received for redeeming sftUSD shares.
GET /ftusd/preview/unstake?chainId={chainId}&shares={shares}
Parameters:
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| chainId | int | No | 1 | Chain ID |
| shares | string | Yes | - | sftUSD shares to redeem in wei (base-10 integer) |
Response:
{
"success": true,
"chain_id": 1,
"input": "950000000000000000",
"output": "1000000000000000000"
}These endpoints support session key delegation via the SessionManager contract.
Retrieve session configuration by session ID.
GET /ftusd/sessions/{sessionId}?chainId={chainId}
Parameters:
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| sessionId | string (path) | Yes | - | Session ID (0x + 64 hex chars) |
| chainId | int (query) | No | 1 | Chain ID |
Response:
{
"success": true,
"chain_id": 1,
"session_id": "0x1234...abcd",
"session": {
"owner": "0x...",
"delegate": "0x...",
"valid_after": 1705708800,
"valid_until": 1706313600,
"max_calls": 100,
"max_fee_bps": 500
}
}Get current nonce for a session (used for replay protection).
GET /ftusd/sessions/{sessionId}/nonce?chainId={chainId}
Response:
{
"success": true,
"chain_id": 1,
"session_id": "0x1234...abcd",
"nonce": "5"
}Get token spending limits and usage for a session.
GET /ftusd/sessions/{sessionId}/limits/{token}?chainId={chainId}
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
| sessionId | string (path) | Yes | Session ID (0x + 64 hex chars) |
| token | string (path) | Yes | Token address |
| chainId | int (query) | No | Chain ID (default 1) |
Response:
{
"success": true,
"chain_id": 1,
"session_id": "0x1234...abcd",
"token": "0x...",
"limit": "1000000000000000000000",
"spent": "500000000000000000000",
"remaining": "500000000000000000000"
}Compute the session ID from owner, delegate, and salt.
POST /ftusd/sessions/compute-id?chainId={chainId}
Request Body:
{
"owner": "0x...",
"delegate": "0x...",
"salt": "0x0000000000000000000000000000000000000000000000000000000000000001"
}Response:
{
"success": true,
"chain_id": 1,
"session_id": "0x1234...abcd"
}Check if a session has been revoked.
GET /ftusd/sessions/{sessionId}/revoked?chainId={chainId}
Response:
{
"success": true,
"chain_id": 1,
"session_id": "0x1234...abcd",
"revoked": false
}import { useQuery } from '@tanstack/react-query';
export function useFtUSDMintPreview(
chainId: number,
collateralToken: string,
amount: string
) {
return useQuery({
queryKey: ['ftusd-preview-mint', chainId, collateralToken, amount],
queryFn: async () => {
const res = await fetch(
`${API_URL}/ftusd/preview/mint?chainId=${chainId}&collateralToken=${collateralToken}&amount=${amount}`
);
if (!res.ok) throw new Error('Failed to preview mint');
return res.json();
},
enabled: !!collateralToken && !!amount && amount !== '0',
});
}
export function useFtUSDStakePreview(chainId: number, amount: string) {
return useQuery({
queryKey: ['ftusd-preview-stake', chainId, amount],
queryFn: async () => {
const res = await fetch(
`${API_URL}/ftusd/preview/stake?chainId=${chainId}&amount=${amount}`
);
if (!res.ok) throw new Error('Failed to preview stake');
return res.json();
},
enabled: !!amount && amount !== '0',
});
}export function useSession(sessionId: string, chainId = 1) {
return useQuery({
queryKey: ['ftusd-session', sessionId, chainId],
queryFn: async () => {
const res = await fetch(
`${API_URL}/ftusd/sessions/${sessionId}?chainId=${chainId}`
);
if (!res.ok) throw new Error('Failed to fetch session');
return res.json();
},
enabled: !!sessionId,
});
}
export function useSessionTokenLimits(
sessionId: string,
token: string,
chainId = 1
) {
return useQuery({
queryKey: ['ftusd-session-limits', sessionId, token, chainId],
queryFn: async () => {
const res = await fetch(
`${API_URL}/ftusd/sessions/${sessionId}/limits/${token}?chainId=${chainId}`
);
if (!res.ok) throw new Error('Failed to fetch limits');
return res.json();
},
enabled: !!sessionId && !!token,
});
}Full API documentation available at: /swagger/index.html
- All amounts/shares are strings to preserve precision (wei values, base-10)
- Session IDs must be valid 32-byte hex values (0x + 64 hex characters)
- Preview endpoints call view functions on-chain - they don't require user signatures
- Multi-chain: Use chainId parameter to query different networks without wallet switching