一键导入
gdex-spot-trading
Buy and sell tokens on Solana, Sui, and EVM chains with automatic DEX routing, slippage control, and percentage-based sells
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Buy and sell tokens on Solana, Sui, and EVM chains with automatic DEX routing, slippage control, and percentage-based sells
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
HyperLiquid perpetual futures — open/close positions, set leverage, place market and limit orders with TP/SL, and manage open orders
CSS theming system for GDEX trading UIs — dark/light modes, trading colors, responsive breakpoints, and Tailwind CSS configuration
Troubleshoot GDEX SDK errors — error codes, encryption debugging, chain-specific quirks, HL gotchas, and copy trade pitfalls
Start here — GDEX overview, architecture, supported chains, available skills, and quickstart for cross-chain DeFi trading via managed-custody wallets
HyperLiquid HIP-3 outcome / event markets — list markets, place outcome orders, and manage outcome positions
Deposit and withdraw USDC to/from HyperLiquid for perpetual futures trading — constraints, amounts, and managed-custody flow
| name | gdex-spot-trading |
| description | Buy and sell tokens on Solana, Sui, and EVM chains with automatic DEX routing, slippage control, and percentage-based sells |
Buy and sell tokens across Solana, Sui, and 12+ EVM chains. The SDK routes through the best available DEX automatically, or you can specify one.
@gdexsdk/gdex-skill installedloginWithApiKey() or managed-custody sign-inimport { GdexSkill, GDEX_API_KEY_PRIMARY } from '@gdexsdk/gdex-skill';
const skill = new GdexSkill();
skill.loginWithApiKey(GDEX_API_KEY_PRIMARY);
const trade = await skill.buyToken({
chain: 'solana', // chain name or ChainId number
tokenAddress: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', // USDC on Solana
amount: '0.1', // 0.1 SOL (native token input)
slippage: 1, // 1% max slippage (optional, default: 1)
dex: 'raydium', // optional: prefer a specific DEX
});
// Returns: { jobId, status, inputAmount, outputAmount, txHash?, error? }
| Parameter | Type | Required | Description |
|---|---|---|---|
chain | string | ChainId | Yes | 'solana', 'sui', or ChainId number (1=Ethereum, 8453=Base, 42161=Arbitrum, 56=BSC, 622112261=Solana) |
Critical: The Solana numeric chainId is
622112261(ChainId.SOLANA), NOT900. Using900returns the EVM managed address withbalance: null. The/v1/userendpoint returns a different managed wallet per chainId (e.g.CFSi4Y...for Solana,0x9967...for EVM). | |tokenAddress|string| Yes | Contract address of the token to buy | |amount|string| Yes | Amount of native token to spend (e.g.,'0.1'for 0.1 SOL) | |slippage|number| No | Max slippage % (default: 1) | |dex|string| No | Force specific DEX:'raydium','orca','uniswap-v3','cetus', etc. | |walletAddress|string| No | Override wallet address | |priorityFee|number| No | Solana priority fee in lamports |
// Sell absolute amount
const trade = await skill.sellToken({
chain: 8453, // Base
tokenAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC on Base
amount: '100', // sell 100 tokens
slippage: 0.5,
});
// Sell percentage of holdings
const trade = await skill.sellToken({
chain: 'solana',
tokenAddress: 'DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263', // BONK
amount: '50%', // sell 50% of holdings
});
| Parameter | Type | Required | Description |
|---|---|---|---|
chain | string | ChainId | Yes | Chain identifier |
tokenAddress | string | Yes | Token contract address |
amount | string | Yes | Absolute amount ('100') or percentage ('50%') |
slippage | number | No | Max slippage % (default: 1) |
walletAddress | string | No | Override wallet address |
For full managed-custody trading with encrypted payloads:
import {
GdexSkill,
GDEX_API_KEY_PRIMARY,
buildGdexManagedTradeComputedData,
} from '@gdexsdk/gdex-skill';
const skill = new GdexSkill();
skill.loginWithApiKey(GDEX_API_KEY_PRIMARY);
// Build encrypted trade payload (requires session key from sign-in)
const trade = buildGdexManagedTradeComputedData({
apiKey: GDEX_API_KEY_PRIMARY,
action: 'purchase', // or 'sell'
userId: '0xYourAddress',
tokenAddress: 'DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263',
amount: '100000', // in smallest unit
nonce: String(Math.floor(Date.now() / 1000) + Math.floor(Math.random() * 1000)),
sessionPrivateKey, // from generateGdexSessionKeyPair()
});
const result = await skill.submitManagedPurchase({
computedData: trade.computedData,
chainId: 622112261, // 622112261=Solana (ChainId.SOLANA), NOT 900
slippage: 15, // 10-15% recommended for Solana
});
token.dexId — if "meteora", the swap will fail with Program error: 1. Tokens with dexId: "raydium" work correctly.'5000000' for 0.005 SOL.chainId: 622112261, not 900. Using 900 will submit the trade to the wrong chain context.
if (result.requestId) {
const status = await skill.getManagedTradeStatus(result.requestId);
console.log('Status:', status.status, 'Hash:', status.hash);
}
Status values:
'queued' — submitted to queue'pending' — being processed'completed' — executed on-chain'failed' — failed (check error field)| Chain | Available DEXes |
|---|---|
| Solana | Raydium, Raydium v2, Orca |
| Sui | Cetus, Bluefin |
| Ethereum | Uniswap v2, Uniswap v3, Odos |
| Base | Uniswap v3, Odos, Arcadia |
| Arbitrum | Uniswap v3, Odos |
| BSC | PancakeSwap, Odos |
| Optimism | Uniswap v3, Odos |
| Fraxtal | Uniswap v3 |
import { GdexValidationError, GdexApiError, GdexRateLimitError } from '@gdexsdk/gdex-skill';
try {
await skill.buyToken({ chain: 'solana', tokenAddress: '...', amount: '0.1' });
} catch (err) {
if (err instanceof GdexRateLimitError) {
await delay(err.retryAfter * 1000); // wait and retry
} else if (err instanceof GdexValidationError) {
console.error('Invalid param:', err.message);
} else if (err instanceof GdexApiError) {
console.error('API error:', err.status, err.message);
}
}
'0.1', '1000')'solana') or ChainId number (622112261)dex specified, the backend selects the best route automaticallyFor buildGdexManagedTradeComputedData() + submitManagedPurchase() / submitManagedSell(), the amount must be in raw units (lamports for Solana, wei for EVM), NOT human-readable:
// ❌ WRONG: amount: '0.01' (this is a float, not raw units)
// ✅ CORRECT: amount: '10000000' (0.01 SOL = 10,000,000 lamports)
// ✅ CORRECT: amount: '10000000000000000' (0.01 ETH = 10^16 wei)
Program error: 1 (backend bug — doesn't wrap SOL into WSOL)token.dexId === 'raydium' ✅ / token.dexId === 'meteora' ❌Program error: 1, the token is Meteora-routed — don't retry, pick a different tokenKeep at least 0.01 SOL in the managed Solana wallet. First trade on a new token costs ~0.007 SOL overhead (ATA creation + priority fee + base tx fee) on top of the trade amount.
After a managed trade returns a requestId, poll until status === 'completed':
if (result.requestId) {
let status;
do {
await new Promise(r => setTimeout(r, 3000)); // wait 3s between polls
status = await skill.getManagedTradeStatus(result.requestId);
} while (status.status === 'queued' || status.status === 'pending');
console.log('Final:', status.status, status.hash);
}
To sell a portion of holdings, use amount: '50%' (string with % sign). The backend calculates the exact token amount.