Error Handling
All SDK methods throw ThetanutsError or a typed subclass. Use the code property or instanceof to branch on specific errors.
Error Codes
ORDER_EXPIRED
Order has expired
Order's expiry timestamp has passed
SLIPPAGE_EXCEEDED
Price moved beyond tolerance
Market moved during transaction
INSUFFICIENT_ALLOWANCE
Token approval needed
Haven't approved tokens for contract
INSUFFICIENT_BALANCE
Not enough tokens
Wallet balance too low
NETWORK_UNSUPPORTED
Chain not supported
Using unsupported chain ID
HTTP_ERROR
API request failed
Network issues, API downtime
BAD_REQUEST
Invalid API request
Malformed parameters
NOT_FOUND
Resource not found
Invalid order ID or address
RATE_LIMIT
Rate limit exceeded
Too many API requests
CONTRACT_REVERT
Contract call failed
Transaction reverted on-chain
INVALID_PARAMS
Invalid parameters
Wrong types, missing required fields
INVALID_ORDER
Order validation failed
Malformed order structure
ORDER_NOT_FOUND
Order doesn't exist
Order ID not in orderbook
SIZE_EXCEEDED
Fill size too large
Requested more than available
SIGNER_REQUIRED
Signer needed
Write operation without signer
WEBSOCKET_ERROR
WebSocket error
Connection issues
KEY_NOT_FOUND
RFQ key missing
No ECDH keypair generated
INVALID_KEY
Invalid key format
Corrupted or wrong key format
ENCRYPTION_FAILED
Encryption failed
ECDH encryption error
DECRYPTION_FAILED
Decryption failed
Wrong key or corrupted data
UNKNOWN
Unknown error
Unexpected error
Error Classes
Base Class
API Errors
Contract Errors
Client Errors
RFQ Key Errors
Handling Errors with isThetanutsError
Handling Errors with instanceof
Use typed error classes for branch-specific recovery logic:
Retry Pattern for Transient Errors
Use exponential backoff for rate limiting and transient network errors:
Contract Revert Reasons
OptionFactory
InvalidImplementation
Unknown option implementation
Use valid implementation from chainConfig.implementations
InvalidCollateral
Unsupported collateral token
Use USDC, WETH, or cbBTC
InvalidExpiry
Expiry in past or too far
Set expiry between now and a reasonable future date
InvalidStrikes
Strike price invalid
Ensure strikes are positive and properly scaled
OfferPeriodEnded
Offer period has closed
Cannot make offer after offerEndTimestamp
OfferPeriodNotEnded
Offer period still open
Wait for period to end before revealing
RevealPeriodEnded
Reveal window closed
Reveal within the reveal window
NoOffersToReveal
No offers submitted
At least one MM offer required to settle
QuotationAlreadySettled
Already settled
Cannot settle twice
NotRequester
Wrong caller
Only the requester can cancel their RFQ
OptionBook
OrderExpired
Order has expired
Fetch fresh orders
OrderCancelled
Order was cancelled
Use a different order
InsufficientSize
Not enough to fill
Reduce fill amount
InvalidOrder
Malformed order
Re-fetch order from API
Option Contract
NotExpired
Option not expired yet
Wait for expiry before calling payout()
AlreadySettled
Already settled
Cannot payout twice
NotBuyer
Caller is not buyer
Only buyer can execute payout
NotBuyerOrSeller
Wrong caller
Only buyer/seller can close
ERC20
ERC20: insufficient allowance
Not approved
Call approve() or ensureAllowance() first
ERC20: transfer amount exceeds balance
Insufficient balance
Check balance before transacting
Common Issues
INSUFFICIENT_ALLOWANCE
Always call ensureAllowance() before fillOrder() or requestForQuotation(). The SDK does not auto-approve.
ORDER_EXPIRED
Check expiry before filling to avoid wasted gas:
SIGNER_REQUIRED
Initialize the client with a signer for any write operation:
Alternatively, use the encode* methods (e.g., encodeFillOrder()) to construct transaction data for an external wallet.
KEY_NOT_FOUND
Generate or restore an ECDH keypair before creating RFQs:
DECRYPTION_FAILED
Verify you are using the same keypair that was used when the RFQ was created:
Debugging
Enable Debug Logging
Inspect Error Details
See Also
Token Operations —
ensureAllowancebefore fillsProduction Checklist — error logging in production
WebSocket —
WEBSOCKET_ERRORreconnection handling
Last updated

