Overview
The OKXDexClient class is the primary entry point for the OKX DEX SDK. It handles authentication, configuration, and provides access to DEX and Bridge APIs.
Constructor
constructor(config: OKXConfig)
Creates a new instance of the OKX DEX client with the provided configuration.
Configuration Parameters
Your OKX API key for authentication
Your OKX secret key for signing requests
Your OKX API passphrase for authentication
baseUrl
string
default:"https://web3.okx.com"
Base URL for OKX API endpoints
Request timeout in milliseconds
Maximum number of retry attempts for failed requests
Sui-specific configuration. See SuiConfig below.
EVM-specific configuration. See EVMConfig below.
Properties
Instance of DexAPI for performing DEX operations like swaps, quotes, and approvals
Instance of BridgeAPI for cross-chain bridge operations
Type Definitions
NetworkConfigs
interface NetworkConfigs {
[chainIndex: string]: ChainConfig;
}
Configuration object mapping chain indices to chain-specific settings.
ChainConfig
Block explorer URL for the chain
Default slippage tolerance for swaps on this chain
Maximum allowed slippage tolerance
Compute units for transaction execution (Solana)
Timeout for transaction confirmation in milliseconds
Maximum retry attempts for chain-specific operations
DEX contract address for the chain
SolanaConfig
Solana wallet instance for signing transactions
Compute units allocated for Solana transactions
Maximum retry attempts for Solana operations
SuiConfig
Private key for Sui wallet
Sui network connection settingsRPC endpoint URL for Sui network
WebSocket endpoint for real-time updates
EVMConfig
EVM wallet instance for signing transactions on EVM-compatible chains
Examples
Basic Initialization
import { OKXDexClient } from '@okxweb3/dex-sdk';
const client = new OKXDexClient({
apiKey: 'your-api-key',
secretKey: 'your-secret-key',
apiPassphrase: 'your-passphrase',
projectId: 'your-project-id'
});
// Access DEX API
const quote = await client.dex.getQuote({
chainIndex: '1',
fromTokenAddress: '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
toTokenAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
amount: '1000000000000000000',
slippagePercent: '0.5'
});
// Access Bridge API
const bridgeQuote = await client.bridge.getQuote({
fromChainIndex: '1',
toChainIndex: '56',
fromTokenAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
toTokenAddress: '0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d',
amount: '1000000'
});
Advanced Configuration
import { OKXDexClient } from '@okxweb3/dex-sdk';
import { Keypair } from '@solana/web3.js';
const solanaKeypair = Keypair.fromSecretKey(
new Uint8Array([/* your secret key */])
);
const client = new OKXDexClient({
apiKey: 'your-api-key',
secretKey: 'your-secret-key',
apiPassphrase: 'your-passphrase',
projectId: 'your-project-id',
timeout: 60000,
maxRetries: 5,
solana: {
wallet: {
getAddress: () => solanaKeypair.publicKey.toBase58(),
signTransaction: async (tx) => {
tx.sign(solanaKeypair);
return tx;
}
},
computeUnits: 200000,
maxRetries: 3
},
networks: {
'501': {
id: 'solana',
explorer: 'https://solscan.io',
defaultSlippage: '0.5',
maxSlippage: '5.0',
computeUnits: 200000,
confirmationTimeout: 60000
}
}
});
Custom Base URL
const client = new OKXDexClient({
apiKey: 'your-api-key',
secretKey: 'your-secret-key',
apiPassphrase: 'your-passphrase',
projectId: 'your-project-id',
baseUrl: 'https://custom-proxy.example.com'
});
See Also