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:
Verify installation
Run:
Copy npm list @opinion-labs/opinion-clob-sdk Install the package
If not installed, run:
Copy npm install @opinion-labs/opinion-clob-sdk Monorepo/workspace check
If using a monorepo or workspace, ensure the dependency is in the correct package.json.
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:
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:
target must be ES2020 or later (for BigInt support).
moduleResolution should be node16 or bundler.
skipLibCheck: true helps 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:
Provide required fields to Client
Load environment variables
Use a library like dotenv to load it:
API and Trading Errors
Common errno Values
Verify API key, check for extra whitespace
Verify market ID exists and is correct
Market is not in ACTIVATED status
Verify order ID (trans_no)
Order is already filled, canceled, or expired
Deposit more funds or cancel other open orders
Price must be between 0 and 1 for prediction markets
Increase order amount (minimum 1 unit)
Reduce request frequency, implement backoff
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:
Check signer wallet balance
Check the BNB balance of your signer wallet (the wallet corresponding to privateKey).
Deposit BNB to the signer wallet address.
Know which ops require gas
Gas is required for enableTrading(), split(), merge(), and redeem().
Note about orders
Placing and canceling orders does NOT require gas (they are off-chain signed operations).
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:
The SDK sends automatic heartbeat messages (default every 30 seconds).
Reconnect on close
Use the onClose callback to detect disconnections and implement reconnection logic:
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.
If you are unable to resolve your issue with the information above:
Documentation: https://docs.opinion.trade
GitHub Issues: Report bugs on the SDK repository