Skip to main content
This example demonstrates a complete integration workflow using Monaco Protocol SDK’s core features: authentication, deposits, withdrawals, and trading.

Installation

Complete Example

React Hook Example

For React applications, here’s a reusable hook:

Key Points

Authentication

  • Use sdk.login(clientId) - it registers a local session key and signs every authenticated request (public market reads are unsigned); there are no tokens to copy or refresh
  • The WebSocket is NOT auto-connected by default — pass sdk.login(clientId, { connectWebSocket: true }) (or connect explicitly) before using sdk.ws.orders() to subscribe
  • Handle 401/403 status codes for authentication errors

Deposits & Withdrawals

  • Get assetId from trading pairs via sdk.market.getTradingPairBySymbol() - use quoteAssetId or baseAssetId
  • assetId (UUID) is used for vault operations: approve(), deposit(), withdraw(), getAllowance(), and needsApproval()
  • Check balances using sdk.profile.getUserBalanceByAssetId(assetId) for detailed balance info (available, locked, total)
  • Always check needsApproval() before depositing
  • Use parseUnits() with correct decimals for token amounts
  • Vault operations require authentication

Trading

  • All amounts are strings (e.g., '1.5', '2000.50')
  • Trading operations require authentication
  • Orders return an orderId for tracking
  • Time-In-Force (TIF) options: 'GTC' (default), 'IOC', or 'FOK'
    • GTC: Order stays active until filled or canceled
    • IOC: Fill immediately, cancel unfilled portion
    • FOK: Fill completely or reject entirely

Error Handling

  • Check error.statusCode for HTTP errors (401, 403)
  • All operations can throw APIError, ContractError, etc.

Next Steps

This example covers the core SDK functionality. For detailed guides on each feature:
Comprehensive example repositories with Vite and Next.js are in development for more complete project setups.