Trading

The trading resource handles swaps, transfers, and cross-chain bridges.

Supported DEXes

ChainDEX ProviderFeatures
SolanaJupiterBest price routing across all Solana DEXes
EthereumRelayCross-chain swaps and bridges
BaseRelayCross-chain swaps and bridges
ArbitrumRelayCross-chain swaps and bridges

Self-Custody Signing Flow

In self-custody mode (walletMode: 'local'), swaps and transfers follow a build → sign → submit flow where signing happens locally:

┌─────────┐     ┌─────────┐     ┌─────────────┐     ┌─────────┐
│  Your    │────>│  API    │────>│  Your       │────>│  API    │
│  App     │     │  Server │     │  Device     │     │  Server │
│          │     │         │     │  (signing)  │     │         │
│ swap()   │     │ /build  │     │ sign tx     │     │ /execute│
└─────────┘     └─────────┘     └─────────────┘     └─────────┘
  1. Build: API builds an unsigned transaction (no private keys needed)
  2. Sign: SDK decrypts your local wallet and signs the transaction on your device
  3. Submit: Signed transaction sent to API for blockchain submission

This is handled automatically — the same swap() and transfer() API works in both modes.

EVM chain operations (bridges) currently use custodial mode regardless of your walletMode setting. Local EVM signing is planned for a future release.

Swaps

Swap tokens on the same chain:

const result = await wallet.trading.swap({
  inputToken: 'SOL',
  outputToken: 'USDC',
  amount: '1.5',
  slippage: 0.5, // Optional, default 0.5%
});
 
console.log('Input:', result.inputAmount, 'SOL');
console.log('Output:', result.outputAmount, 'USDC');
console.log('Transaction:', result.txHash);

Slippage Recommendations

Token TypeRecommended SlippageNotes
Stablecoins (USDC, USDT)0.1% - 0.5%Low volatility, tight spreads
Major tokens (SOL, ETH)0.5% - 1%Moderate volatility
Volatile/low liquidity1% - 3%Higher slippage needed to ensure execution
Meme tokens3% - 5%+High volatility, consider using quoteOnly first

Price Impact Warning: Always check priceImpact in the quote response before executing large trades. A price impact above 1% indicates significant market movement. Above 5% suggests you should consider splitting the trade into smaller amounts.

Quote Only

Get a quote without executing:

const quote = await wallet.trading.swap({
  inputToken: 'SOL',
  outputToken: 'USDC',
  amount: '1.5',
  quoteOnly: true,
});
 
console.log('Expected output:', quote.outputAmount, 'USDC');
console.log('Price impact:', quote.priceImpact, '%');

EVM Swaps

const result = await wallet.trading.swap({
  inputToken: 'ETH',
  outputToken: 'USDC',
  amount: '0.1',
  chain: 'ethereum', // Specify chain for EVM
});

Gas Estimation: On EVM chains, gas fees are estimated automatically based on current network conditions. The SDK uses a priority fee multiplier to ensure timely execution. During high congestion, transactions may take longer or require higher gas. Consider using quoteOnly to preview the expected gas cost before executing.

Transfers

Send tokens to another address:

const result = await wallet.trading.transfer({
  to: 'recipient_address',
  token: 'USDC',
  amount: '100',
  chain: 'solana',
});
 
console.log('Sent:', result.amount, result.token);
console.log('Transaction:', result.txHash);

Send Native Tokens

// Send SOL
await wallet.trading.transfer({
  to: 'recipient',
  token: 'SOL',
  amount: '1',
  chain: 'solana',
});
 
// Send ETH
await wallet.trading.transfer({
  to: '0x...',
  token: 'ETH',
  amount: '0.1',
  chain: 'ethereum',
});

Bridges

Bridge tokens between EVM chains:

const result = await wallet.trading.bridge({
  fromChain: 'ethereum',
  toChain: 'base',
  token: 'USDC',
  amount: '100',
});
 
console.log('Bridge initiated');
console.log('Source tx:', result.sourceTxHash);
console.log('Estimated time:', result.estimatedTime);

Bridges are only available between EVM chains. Solana bridges are not yet supported.

Token Resolution

The SDK resolves token names to addresses:

// All these work
await wallet.trading.swap({ inputToken: 'SOL', ... });
await wallet.trading.swap({ inputToken: 'USDC', ... });
await wallet.trading.swap({
  inputToken: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',  // USDC address
  ...
});

Type Definitions

interface SwapParams {
  inputToken: string;
  outputToken: string;
  amount: string;
  chain?: string;
  slippage?: number;
  quoteOnly?: boolean;
}
 
interface SwapResult {
  inputAmount: string;
  outputAmount: string;
  txHash?: string;
  chain: string;
  priceImpact?: number;
}
 
interface TransferParams {
  to: string;
  token: string;
  amount: string;
  chain: string;
}
 
interface BridgeParams {
  fromChain: string;
  toChain: string;
  token: string;
  amount: string;
}