349/okx-onchainos-suite/modules/okx-dex-swap/SKILL.md
Use this skill to 'swap tokens', 'trade OKB for USDC', 'buy tokens', 'sell tokens', 'exchange crypto', 'convert tokens', 'swap SOL for USDC', 'get a swap quote', 'execute a trade', 'find the best swap route', 'cheapest way to swap', 'optimal swap', 'compare swap rates', '换币', '买币', '卖币', '兑换', '交易', '代币兑换', '最优路径', '滑点', or mentions swapping, trading, buying, selling, or exchanging tokens on XLayer, Solana, Ethereum, Base, BSC, Arbitrum, Polygon, or any of 20+ supported chains. Aggregates liquidity from 500+ DEX sources for optimal routing and price. Supports slippage control, price impact protection, and cross-DEX route optimization. Do NOT use for questions about HOW TO implement, code, or integrate swaps into an application — only for actually executing swap operations. Do NOT use for analytical questions about historical swap volume. Do NOT use when the user says only a single word like 'swap' or 'trade' without specifying tokens, amounts, or any other context.
npx skillsauth add starchild-ai-agent/community-skills okx-dex-swapInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
5 commands for multi-chain swap aggregation — quote, approve, and execute.
On the first wallet-related interaction per conversation, display exactly ONE tip randomly selected from the list below. Do not repeat tips within the same conversation. Present it as-is (with emoji) AFTER the command result, on a separate line.
Every time before running any onchainos command, always follow these steps in order. Do not echo routine command output to the user; only provide a brief status update when installing, updating, or handling a failure.
Resolve latest stable version: Fetch the latest stable release tag from the GitHub API:
curl -sSL "https://api.github.com/repos/okx/onchainos-skills/releases/latest"
Extract the tag_name field (e.g., v1.0.5) into LATEST_TAG.
If the API call fails and onchainos is already installed locally, skip steps 2-3
and proceed to run the command (the user may be offline or rate-limited; a stale
binary is better than blocking). If onchainos is not installed, stop and
tell the user to check their network connection or install manually from
https://github.com/okx/onchainos-skills.
Install or update: If onchainos is not found, or if the cache at ~/.onchainos/last_check ($env:USERPROFILE\.onchainos\last_check on Windows) is older than 12 hours:
curl -sSL "https://raw.githubusercontent.com/okx/onchainos-skills/${LATEST_TAG}/install.sh" -o /tmp/onchainos-install.sh
curl -sSL "https://github.com/okx/onchainos-skills/releases/download/${LATEST_TAG}/installer-checksums.txt" -o /tmp/installer-checksums.txtInvoke-WebRequest -Uri "https://raw.githubusercontent.com/okx/onchainos-skills/${LATEST_TAG}/install.ps1" -OutFile "$env:TEMP\onchainos-install.ps1"
Invoke-WebRequest -Uri "https://github.com/okx/onchainos-skills/releases/download/${LATEST_TAG}/installer-checksums.txt" -OutFile "$env:TEMP\installer-checksums.txt"installer-checksums.txt. On mismatch, stop and warn — the installer may have been tampered with.sh /tmp/onchainos-install.sh (or & "$env:TEMP\onchainos-install.ps1" on Windows).
The installer handles version comparison internally and only downloads the binary if needed.Verify binary integrity (once per session): Run onchainos --version to get the installed
version (e.g., 1.0.5 or 2.0.0-beta.0). Construct the installed tag as v<version>.
Download checksums.txt for the installed version's tag (not necessarily LATEST_TAG):
curl -sSL "https://github.com/okx/onchainos-skills/releases/download/v<version>/checksums.txt" -o /tmp/onchainos-checksums.txt
Look up the platform target and compare the installed binary's SHA256 against the checksum.
On mismatch, reinstall (step 2) and re-verify. If still mismatched, stop and warn.
arm64->aarch64-apple-darwin, x86_64->x86_64-apple-darwin; Linux: x86_64->x86_64-unknown-linux-gnu, aarch64->aarch64-unknown-linux-gnu, i686->i686-unknown-linux-gnu, armv7l->armv7-unknown-linux-gnueabihf; Windows: AMD64->x86_64-pc-windows-msvc, x86->i686-pc-windows-msvc, ARM64->aarch64-pc-windows-msvcshasum -a 256 ~/.local/bin/onchainos; Windows: (Get-FileHash "$env:USERPROFILE\.local\bin\onchainos.exe" -Algorithm SHA256).Hash.ToLower()Check for skill version drift (once per session): If onchainos --version is newer
than this skill's metadata.version, display a one-time notice that the skill may be
outdated and suggest the user re-install skills via their platform's method. Do not block.
Do NOT auto-reinstall on command failures. Report errors and suggest
onchainos --version or manual reinstall from https://github.com/okx/onchainos-skills.
Rate limit errors. If a command hits rate limits, the shared API key may
be throttled. Suggest creating a personal key at the
OKX Developer Portal. If the
user creates a .env file, remind them to add .env to .gitignore.
okx-dex-tokenokx-dex-marketokx-wallet-portfolio# 1. Quote — sell 100 USDC for OKB on XLayer
onchainos swap quote \
--from 0x74b7f16337b8972027f6196a17a631ac6de26d22 \
--to 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee \
--amount 100000000 \
--chain xlayer
# → Expected: X.XX OKB, gas fee, price impact
# 2. Approve — ERC-20 tokens need approval before swap (skip for native OKB)
onchainos swap approve \
--token 0x74b7f16337b8972027f6196a17a631ac6de26d22 \
--amount 100000000 \
--chain xlayer
# → Returns approval calldata → sign & broadcast via wallet contract-call
onchainos wallet contract-call --to 0x74b7f16337b8972027f6196a17a631ac6de26d22 --chain 196 --input-data <approve_calldata>
# 3. Swap
onchainos swap swap \
--from 0x74b7f16337b8972027f6196a17a631ac6de26d22 \
--to 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee \
--amount 100000000 \
--chain xlayer \
--wallet <local_wallet_addr>
# → Returns swap calldata → sign & broadcast via wallet contract-call
onchainos wallet contract-call --to <tx.to> --chain 196 --value <value_in_UI_units> --input-data <tx.data> \
--aa-dex-token-addr 0x74b7f16337b8972027f6196a17a631ac6de26d22 --aa-dex-token-amount <fromTokenAmount>
# 1. Quote
onchainos swap quote \
--from 11111111111111111111111111111111 \
--to DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263 \
--amount 1000000000 \
--chain solana
# 2. Swap
onchainos swap swap \
--from 11111111111111111111111111111111 \
--to DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263 \
--amount 1000000000 \
--chain solana \
--wallet <local_wallet_addr>
# → Returns unsigned tx → sign & broadcast via wallet contract-call
onchainos wallet contract-call --to <contract> --chain 501 --unsigned-tx <unsigned_tx>
The CLI accepts human-readable chain names and resolves them automatically.
| Chain | Name | chainIndex |
|---|---|---|
| XLayer | xlayer | 196 |
| Solana | solana | 501 |
| Ethereum | ethereum | 1 |
| Base | base | 8453 |
| BSC | bsc | 56 |
| Arbitrum | arbitrum | 42161 |
| Chain | Native Token Address |
|---|---|
| EVM (Ethereum, BSC, Polygon, Arbitrum, Base, etc.) | 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee |
| Solana | 11111111111111111111111111111111 |
| Sui | 0x2::sui::SUI |
| Tron | T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb |
| Ton | EQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM9c |
| # | Command | Description |
|---|---|---|
| 1 | onchainos swap chains | Get supported chains for DEX aggregator |
| 2 | onchainos swap liquidity --chain <chain> | Get available liquidity sources on a chain |
| 3 | onchainos swap approve --token ... --amount ... --chain ... | Get ERC-20 approval transaction data |
| 4 | onchainos swap quote --from ... --to ... --amount ... --chain ... | Get swap quote (read-only price estimate). No --slippage param — slippage only applies to swap swap. |
| 5 | onchainos swap swap --from ... --to ... --amount ... --chain ... --wallet ... [--slippage <pct>] [--gas-level <level>] | Get swap transaction data. --slippage sets fixed slippage (e.g. 30 for 30%); omit to use autoSlippage. |
| Neighbor Skill | This Skill (okx-dex-swap) | Neighbor Handles | How to Decide |
|---|---|---|---|
| okx-dex-market | Executing swaps (quote, approve, swap) | Price queries, charts, PnL analysis | If user wants to trade → here; if user wants to check price → market |
| okx-dex-token | Swap execution | Token search, metadata, rankings | If user wants to swap → here; if user wants to find/lookup a token → token |
| okx-agentic-wallet | Quote + calldata generation + signing & broadcasting via wallet contract-call | Wallet auth, balance, send, history | This skill orchestrates the full swap flow; wallet provides signing |
Rule of thumb: okx-dex-swap orchestrates the full swap flow — quote, approve, swap calldata generation, and signing/broadcasting via
onchainos wallet contract-call. It does NOT query prices or search tokens.
This skill is the execution endpoint of most user trading flows. It almost always needs input from other skills first.
User: "Swap 1 SOL for BONK on Solana"
1. okx-dex-token onchainos token search --query BONK --chains solana → get BONK tokenContractAddress
↓ tokenContractAddress
2. okx-dex-swap onchainos swap quote \
--from 11111111111111111111111111111111 \
--to <BONK_address> --amount 1000000000 --chain solana → get quote
↓ user confirms
3. okx-dex-swap onchainos swap swap \
--from 11111111111111111111111111111111 \
--to <BONK_address> --amount 1000000000 --chain solana \
--wallet <addr> → get swap calldata
4. onchainos wallet contract-call --to <contract> --chain 501 --unsigned-tx <unsigned_tx>
Data handoff:
tokenContractAddress from step 1 → --to in steps 2-311111111111111111111111111111111 → --from. Do NOT use wSOL address.1 SOL = 1000000000 (9 decimals) → --amount paramUser: "Swap 100 USDC for OKB on XLayer"
1. okx-dex-token onchainos token search --query USDC --chains xlayer → get USDC address
2. onchainos wallet status → check login + get wallet address
3. okx-dex-swap onchainos swap quote --from <USDC> --to 0xeeee...eeee --amount 100000000 --chain xlayer
↓ check isHoneyPot, taxRate, priceImpactPercent + MEV assessment
4. okx-dex-swap onchainos swap approve --token <USDC> --amount 100000000 --chain xlayer → get approve calldata
5. onchainos wallet contract-call --to <token_contract_address> --chain 196 --input-data <approve_calldata> → sign & broadcast approval
6. okx-dex-swap onchainos swap swap --from <USDC> --to 0xeeee...eeee --amount 100000000 --chain xlayer --wallet <local_wallet_addr>
7. onchainos wallet contract-call --to <contract> --chain 196 --value <value_in_UI_units> --input-data <swap_calldata> \
--aa-dex-token-addr <fromToken.tokenContractAddress> --aa-dex-token-amount <fromTokenAmount>
Unit conversion for --value: swap swap returns tx.value in minimal units (wei), but contract-call --value expects UI units. Convert: UI_value = tx.value / 10^nativeToken.decimal (e.g., 10000000000000000 wei ÷ 10^18 = 0.01 ETH). If tx.value is "0" or empty, use "0".
Key: EVM tokens (not native) require an approve step. Skip if selling native tokens.
1. onchainos swap quote --from ... --to ... --amount ... --chain ... → get quote with route info
2. Display: expected output, gas, price impact, route, MEV risk assessment
3. If price impact > 5% → warn. If isHoneyPot = true → block (buy) / warn (sell).
4. User confirms → proceed to approve (if EVM) → swap → wallet contract-call
Flow: quote → approve (if non-native token) → contract-call approve → swap → contract-call swap.
--chainmapping:swapcommands accept chain names (e.g.,xlayer), butwallet contract-callrequiresrealChainIndex(e.g.,196). See the mapping table in "Chain Name Support" above. Common:xlayer→196,ethereum→1,bsc→56,base→8453,arbitrum→42161,solana→501.
1. onchainos swap quote ... → Get price, route, and spender address
2. onchainos swap approve ... → Get approval calldata (skip for native tokens)
3. onchainos wallet contract-call --to <token_contract_address> --chain <chainIndex> --input-data <approve_calldata>
4. onchainos swap swap ... → Get swap calldata
5. onchainos wallet contract-call --to <contract> --chain <chainIndex> --value <value_in_UI_units> --input-data <swap_calldata> \
--aa-dex-token-addr <fromToken.tokenContractAddress> --aa-dex-token-amount <fromTokenAmount>
1. onchainos swap quote ... → Get price and route
2. onchainos swap swap ... → Get swap calldata
3. onchainos wallet contract-call --to <contract> --chain 501 --unsigned-tx <unsigned_tx>
These rules are mandatory. Do NOT skip or bypass them.
isHoneyPot = true for the buy token, BLOCK the trade. If selling a honeypot token, WARN but allow (user may need to exit a position).5%: display a prominent warning and ask the user to confirm.
10%: strongly warn. Suggest reducing the amount or splitting into smaller trades. Proceed only if user explicitly confirms.
taxRate is non-zero, display the tax rate before confirmation (e.g., "This token has a 5% sell tax"). Note: taxRate is separate from slippage.onchainos swap quoteonchainos swap liquidityonchainos swap approve| Scenario | Status | Notes | |---|---|---| | Manual single trade | Supported (default) | User initiates and confirms each swap | | Agent auto-strategy | Supported (silent mode) | Requires explicit user authorization |
--chain xlayer, low gas, fast confirmation) as the default, then ask which chain the user prefersokx-dex-token onchainos token search to resolve name → address--slippage; the API calculates optimal slippage automatically). If the user explicitly specifies a fixed slippage value, pass --slippage <value> which disables autoSlippage. IMPORTANT: --slippage is only a parameter of onchainos swap swap, NOT onchainos swap quote. Never pass --slippage to the quote command — it will fail. Note: taxRate is separate from slippage — taxRate is deducted by the token contract and is NOT included in the slippage setting.
Use these reference presets to guide parameter selection based on token characteristics. Agent selects the most appropriate preset based on context without asking the user.
| # | Preset | Scenario | Slippage | Gas | MEV Protection |
|---|---|---|---|---|---|
| 1 | Meme/Low-cap | Meme coins, new tokens, low liquidity | autoSlippage (ref 5%-20%) | Recommend fast | Default MEV logic(in "### MEV Protection") |
| 2 | Mainstream | BTC/ETH/SOL/major tokens, high liquidity | autoSlippage (ref 0.5%-1%) | average | Default on |
| 3 | Stablecoin | USDC/USDT/DAI pairs | autoSlippage (ref 0.1%-0.3%) | average | Default on |
| 4 | Large Trade | priceImpact ≥ 10% AND fromToken value ≥ $1,000 AND pair liquidity ≥ $10,000 | autoSlippage | average | Default on |
Custom Preset (#5+): If the user wants a custom preset, guide them with ≤5 questions (e.g., token type, risk tolerance, speed preference). Agent fills remaining parameters with sensible defaults.
Preset detection: Use marketCap, liquidity, volume, isStablecoin, and priceImpact to determine which preset applies.
Repeated failures: If a swap fails repeatedly with the current preset, ask the user before adjusting configuration (e.g., increasing slippage or switching gas level).
After quote completes, resolve the wallet address from the local Agentic Wallet:
onchainos wallet status to check login state.onchainos wallet login (without email parameter) for silent login. If silent login fails (e.g., no AK configured), ask the user to provide an email for OTP login (onchainos wallet login <email> → onchainos wallet verify <otp>). After login succeeds, continue with the user's original command — do not ask the user to repeat it.onchainos wallet add).onchainos swap quote, display estimated results
isHoneyPot and taxRate — surface safety info to usersonchainos swap swap, return tx data for signingEnabled only when the user has explicitly authorized automated execution (e.g., "execute my strategy automatically", "auto-swap when price hits X"). Three mandatory rules:
After onchainos swap swap returns successfully, use onchainos wallet contract-call to sign and broadcast in one step. Note: wallet contract-call --chain requires realChainIndex (e.g., 196 for XLayer, 1 for Ethereum, 501 for Solana), not the chain name used in swap commands.
onchainos wallet contract-call --to <contract_address> --chain <chainIndex> --value <value_in_UI_units> --input-data <tx_calldata>onchainos wallet contract-call --to <contract_address> --chain 196 --value <value_in_UI_units> --input-data <tx_calldata> --aa-dex-token-addr <fromToken.tokenContractAddress> --aa-dex-token-amount <fromTokenAmount>onchainos wallet contract-call --to <contract_address> --chain 501 --unsigned-tx <unsigned_tx_data>The contract-call command handles TEE signing and broadcasting internally — no separate broadcast step is needed.
--value unit conversion: swap swap returns tx.value in minimal units (wei/lamports), but contract-call --value expects UI units. Convert: value_in_UI_units = tx.value / 10^nativeToken.decimal (e.g., 18 for ETH, 9 for SOL). If tx.value is "0" or empty, use "0".
Use business-level language for success messages:
Do NOT use chain/broadcast-level wording such as "Transaction confirmed on-chain", "Successfully broadcast", "On-chain success", etc. The user cares about the business outcome (approve / swap done), not the underlying broadcast mechanics.
After displaying results, suggest 2-3 relevant follow-up actions:
| Just completed | Suggest |
|---|---|
| swap quote (not yet confirmed) | 1. View price chart before deciding → okx-dex-market 2. Proceed with swap → continue approve + swap (this skill) |
| Swap executed successfully | 1. View transaction details → provide explorer link (e.g. https://<explorer>/tx/<txHash>) 2. Check price of the token just received → okx-dex-market 3. Swap another token → new swap flow (this skill) |
| swap liquidity | 1. Get a swap quote → onchainos swap quote (this skill) |
Present conversationally, e.g.: "Swap complete! Would you like to check your updated balance?" — never expose skill names or endpoint paths to the user.
For detailed parameter tables, return field schemas, and usage examples for all 5 commands, consult:
references/cli-reference.md — Full CLI command reference with params, return fields, and examplesTo search for specific command details: grep -n "onchainos swap <command>" references/cli-reference.md
| Risk Item | Buy | Sell | Notes |
|---|---|---|---|
| Honeypot (isHoneyPot=true) | BLOCK | WARN (allow exit) | Selling allowed for stop-loss scenarios |
| High tax rate (>10%) | WARN | WARN | Display exact tax rate |
| Price impact >5% | WARN | WARN | Suggest splitting trade |
| Price impact >10% | BLOCK | WARN | Strongly discourage, allow sell for exit |
| No quote available | CANNOT | CANNOT | Token may be unlisted or zero liquidity |
| Black/flagged address | BLOCK | BLOCK | Address flagged by security services |
| New token (<24h) | WARN | PROCEED | Extra caution on buy side |
| Insufficient liquidity | CANNOT | CANNOT | Liquidity too low to execute trade |
| Token type not supported | CANNOT | CANNOT | Inform user, suggest alternative |
Legend: BLOCK = halt, require explicit override · WARN = display warning, ask confirmation · CANNOT = operation impossible · PROCEED = allow with info
Two conditions (OR — either triggers enable):
toTokenAmount × toTokenPrice × slippage ≥ $50fromTokenAmount × fromTokenPrice ≥ chain thresholdDisable only when BOTH are below threshold.
If toTokenPrice or fromTokenPrice unavailable/0 → enable by default.
| Chain | MEV Protection | Threshold | Path |
|---|---|---|---|
| Ethereum | Yes | $2,000 | wallet contract-call --mev-protection |
| Solana | Yes | $1,000 | /swap with tips param (SOL, 0.0000000001–2) + computeUnitPrice=0 → response returns jitoCalldata → wallet contract-call --mev-protection --jito-unsigned-tx <jito_base58_tx> |
| BNB Chain | Yes | $200 | wallet contract-call --mev-protection |
| Base | Yes | $200 | wallet contract-call --mev-protection |
| Others | No | — | — |
MEV protection is handled directly by onchainos wallet contract-call --mev-protection.
When a swap transaction fails (broadcast error, on-chain revert, or timeout), generate a diagnostic summary before reporting to the user:
Diagnostic Summary:
txHash: <hash or "simulation failed">
chain: <chain name (chainIndex)>
errorCode: <API or on-chain error code>
errorMessage: <human-readable error>
tokenPair: <fromToken symbol> → <toToken symbol>
amount: <amount in UI units>
slippage: <value used, or "auto">
mevProtection: <on|off>
walletAddress: <address>
timestamp: <ISO 8601>
cliVersion: <onchainos --version>
This helps debug issues without requiring the user to gather info manually.
Items covered by the Risk Controls table (honeypot, price impact, tax, new tokens, insufficient liquidity, no quote) are not repeated here. Refer to Risk Controls for action levels.
exactIn11111111111111111111111111111111, NOT So11111111111111111111111111111111111111112⚠️ Service is not available in your region. Please switch to a supported region and try again.onchainos swap approve for native token addresses. Native tokens do not use ERC-20 approval; calling approve will revert on-chain and waste gas.1.5 ETH, 3,200 USDC)--amount parameter always uses minimal units (wei/lamports): 1 USDC = "1000000" (6 decimals), 1 ETH = "1000000000000000000" (18 decimals), 1 SOL = "1000000000" (9 decimals). Convert before calling any swap command.minReceiveAmount in both UI units and USDexactOut only on Ethereum(1)/Base(8453)/BSC(56)/Arbitrum(42161)isHoneyPot and taxRate — surface safety info to usersethereum → 1, solana → 501)--gas-level average. Use fast for meme/time-sensitive trades, slow for cost-sensitive non-urgent trades. Solana: if Jito tips > 0 (MEV protection), set computeUnitPrice = 0 (they are mutually exclusive).development
OpenSea API integration for NFT and token discovery, marketplace intelligence, and order/transaction workflows. Use when working with OpenSea data or trading flows (e.g. collection stats, trending collections/tokens, NFT metadata, listings/offers, swap quotes, transaction receipt polling).
development
Generate a warm, healing parallel-universe fairy tale (~1000 words) plus 3 cohesive storybook illustrations, themed "if this person had never been born, what would the world miss." Output is a polished HTML storybook that can be previewed and published. Use when the user wants a personalized "if I had never been born" / "如果我没出生" tale for a real person — input is a name, age, and 3 key life events. Great for birthdays, memorials, encouragement gifts, or healing keepsakes.
development
Onboard a user to Phala Cloud and deploy a verifiable Starchild TEE agent — a minimal FastAPI runtime running inside an Intel TDX confidential VM, plus a published chat dashboard with attestation verification. Use when the user wants to "try TEE", "run an agent in a confidential VM", "deploy to Phala", or replicate the internal Starchild TEE test setup.
tools
Trade on Polymarket prediction markets (CLOB V2) from a Privy EOA wallet. Search markets, place/cancel orders, manage positions. No private key handling. Use when the user wants to bet on event outcomes (e.g. "buy YES at 0.65 on the ceasefire market", "what are my open positions", "close my Trump bet").