Prerequisites
Before installing the OKX DEX SDK, ensure you have:Node.js 16 or higher
Node.js 16 or higher
The SDK requires Node.js version 16.0.0 or higher. Check your version:Download the latest version from nodejs.org
OKX API Credentials
OKX API Credentials
You’ll need API credentials from OKX to use the SDK:
- API Key - Your unique API key
- Secret Key - Your API secret for signing requests
- Passphrase - Your API passphrase
- Project ID - Your project identifier
Sign up for API access at OKX Developer Portal. API credentials are required for all DEX operations.
Blockchain Wallet (Optional)
Blockchain Wallet (Optional)
For executing swaps (not just quotes), you’ll need:
- Private Key - For signing transactions
- RPC URL - Connection to the blockchain network
Install the Package
Install the SDK using your preferred package manager:Install Required Dependencies
Depending on which blockchains you plan to use, install the corresponding dependencies:- EVM Chains
- Solana
- Sui
For Ethereum, Base, Polygon, and other EVM-compatible chains:The SDK requires:
- ethers (v6.14.3 or higher) - For EVM wallet and transaction handling
- dotenv - For managing environment variables
Configuration
Environment Variables
Create a.env file in your project root with your credentials:
.env
TypeScript Configuration
Ensure yourtsconfig.json includes proper ES module support:
tsconfig.json
Verify Installation
Create a simple test file to verify your installation:test.ts
Common Installation Issues
Module not found errors
Module not found errors
If you see
Cannot find module errors, ensure all peer dependencies are installed:Authentication errors
Authentication errors
If you get
401 Unauthorized or authentication errors:- Verify your API credentials are correct in
.env - Ensure there are no extra spaces in credential values
- Check that your API key has the necessary permissions
- Verify the Project ID matches your API key
Network/timeout errors
Network/timeout errors
For network connection issues:
- Check your internet connection
- Verify RPC URLs are accessible
- Try increasing the timeout in client configuration:
TypeScript errors
TypeScript errors
If you encounter TypeScript compilation errors:
- Ensure you’re using TypeScript 5.0 or higher
- Check that
esModuleInteropis enabled intsconfig.json - Try deleting
node_modulesand reinstalling:
Advanced Configuration
Custom Timeout and Retries
Configure request timeout and retry behavior:Chain-Specific Configuration
Configure wallets for multiple chains:Next Steps
Start building with the Quickstart guide
Learn how to execute your first token swap with real code examples