Troubleshooting
Common issues and solutions for the TypeScript SDK (@opinion-labs/opinion-clob-sdk v0.5.2).
Installation Issues
Cannot find module '@opinion-labs/opinion-clob-sdk'
Problem: TypeScript or Node.js cannot locate the SDK package.
Solution:
ERR_REQUIRE_ESM or "require() of ES Module not supported"
Problem: The SDK is an ESM (ECMAScript Module) package, but your project uses CommonJS require().
Solution:
Option A - Switch your project to ESM:
Add "type": "module" to your package.json:
{
"type": "module"
}Option B - Use dynamic import in CommonJS:
TypeScript compiler errors with viem types
Problem: Type errors related to Address, Hex, or other viem types.
Solution:
Ensure your tsconfig.json has the following settings:
Key requirements:
targetmust beES2020or later (for BigInt support).moduleResolutionshould benode16orbundler.skipLibCheck: truehelps avoid transitive type conflicts.
Node.js version compatibility
Problem: Runtime errors or unexpected behavior.
Solution: The SDK requires Node.js 18 or later. Check your version:
If below v18, upgrade Node.js. The SDK uses features like native fetch, BigInt, and ES modules.
Configuration Errors
"chainId must be one of 56" (Unsupported Chain ID)
Problem: InvalidParamError thrown during Client initialization.
Cause: Only BNB Chain mainnet (chain ID 56) is currently supported.
Solution:
Missing Environment Variables
Problem: Client initialization fails due to missing credentials.
Solution:
API and Trading Errors
Common errno Values
0
Success
No action needed
100
Invalid API key
Verify API key, check for extra whitespace
200
Market not found
Verify market ID exists and is correct
201
Market not active
Market is not in ACTIVATED status
300
Order not found
Verify order ID (trans_no)
301
Order cannot be canceled
Order is already filled, canceled, or expired
303
Insufficient balance
Deposit more funds or cancel other open orders
304
Price out of range
Price must be between 0 and 1 for prediction markets
305
Amount too small
Increase order amount (minimum 1 unit)
429
Rate limit exceeded
Reduce request frequency, implement backoff
500
Internal server error
Retry after a short delay
InvalidParamError: "makerAmountInBaseToken is not allowed for market buy"
Problem: Attempting a market buy order with makerAmountInBaseToken.
Solution: Market buy orders must use makerAmountInQuoteToken:
InvalidParamError: "makerAmountInQuoteToken is not allowed for market sell"
Problem: Attempting a market sell order with makerAmountInQuoteToken.
Solution: Market sell orders must use makerAmountInBaseToken:
OpenApiError: "Quote token not found for this market"
Problem: The market's quote token is not in the list of supported quote tokens.
Solution:
Ensure you are using the correct chain ID (56).
Call
getQuoteTokens()to see supported tokens.Verify the market's quote token matches one of the supported tokens.
OpenApiError: "Cannot place order on different chain"
Problem: The market belongs to a different chain than the client is configured for.
Solution: Ensure your chainId matches the market's chain. Currently only chain ID 56 (BNB Chain) is supported.
Rate Limiting (errno: 429)
Problem: Too many requests in a short period.
Solution: Implement exponential backoff:
Blockchain Issues
InsufficientGasBalance
Problem: The signer wallet does not have enough BNB for gas fees.
Solution:
Transaction Reverted
Problem: An on-chain transaction reverts.
Common causes and solutions:
split fails: Check that you have enough collateral (USDC) in your asset wallet. The market must be in ACTIVATED, RESOLVING, or RESOLVED status.
merge fails: You need equal amounts of Yes and No tokens. Check your position balances.
redeem fails: Market must be in RESOLVED status. You must hold winning outcome tokens.
enableTrading fails: Check that the signer wallet has enough BNB for gas.
Wrong Contract Addresses
Problem: Transactions fail because of incorrect contract addresses.
Solution: The SDK uses default contract addresses for BNB Chain. If you need to override them:
Only override these if instructed by the Opinion Labs team.
WebSocket Issues
"WebSocket is not connected. Call connect() first."
Problem: Attempting to subscribe or send messages before the WebSocket connection is established.
Solution: Always await the connect() call before subscribing:
WebSocket connection drops
Problem: WebSocket disconnects unexpectedly.
Solution:
Performance Tips
Use Caching
The SDK caches quote tokens (1 hour) and market data (5 minutes) by default. Avoid setting TTLs to 0 unless you need real-time data:
Batch Operations
Use batch methods for multiple orders:
Pre-enable Trading
Call enableTrading() once at startup rather than passing checkApproval: true on every order:
Use Proxy for Network Restrictions
If you are behind a firewall or in a region with network restrictions, configure a proxy:
This applies to both HTTP API calls and WebSocket connections.
Support
If you are unable to resolve your issue with the information above:
Documentation: https://docs.opinion.trade
Email: support@opinion.trade
GitHub Issues: Report bugs on the SDK repository