Bitget wallet

From jiayaoqijia/cryptoskill · View interactive version

Bitget wallet is an AI agent skill from the GitHub repository jiayaoqijia/cryptoskill. Interact with Bitget Wallet API for crypto market data, token info, swap quotes, and security audits. Use when the user asks about token prices, market data, swap/trading quotes, token security checks, K-line charts, or token rankings on supported chains (ETH, SOL, BSC, Base, etc.).

How to use this skill

Skill file

Bitget Wallet Skill

API Overview

Domain Knowledge

What you need to know beyond command syntax to use these tools correctly. These are cross-command constraints, common pitfalls, and the relationships between commands that the CLI README alone doesn't cover.

Version Awareness

This skill uses date-based versioning (YYYY.M.DD). Each release includes a sequential suffix: YYYY.M.DD-1, YYYY.M.DD-2, etc. The current version is in the frontmatter above. See CHANGELOG.md for full history.

Daily first-use version check:

On the first use of the week (at most once every 7 days), compare the installed version (from frontmatter) against the latest version available from the repository:

  1. Check the installed version from frontmatter above
  2. Fetch the latest CHANGELOG.md from https://raw.githubusercontent.com/bitget-wallet-ai-lab/bitget-wallet-skill/main/CHANGELOG.md
  3. Compare the latest version in CHANGELOG with the installed version

If a new version is available, inform the user:

๐Ÿ”„ Bitget Wallet Skill update available
โ€ข Installed: [installed version]
โ€ข Latest: [latest version]
โ€ข Changes: [one-line summary from CHANGELOG]
โ€ข Security-related: [yes/no โ€” highlight if Security section exists]

Upgrade? [yes/no]

If the user confirms upgrade:

Re-install the skill from the main branch of the repository at https://github.com/bitget-wallet-ai-lab/bitget-wallet-skill. Replace all local skill files with the latest versions, then re-read SKILL.md to load the updated Domain Knowledge.

Post-upgrade security check:

If versions match: No announcement needed, proceed normally.

Check frequency: At most once every 7 days. The agent should track the last check date and skip if fewer than 7 days have passed.

First-Time Swap Configuration

The first time a user initiates a swap, before executing, guide them through these one-time preferences:

  1. Transaction deadline โ€” how long the on-chain transaction remains valid:
  1. Automatic security check โ€” whether to audit unfamiliar tokens before swaps:
  1. Save preferences โ€” store in the agent's memory/config for future swaps
  2. Remind user they can update anytime (e.g., "update my swap settings" or "change my default deadline")

If the user declines configuration, use sensible defaults: deadline=300, security=always.

Amounts: Everything is Human-Readable

All BGW API inputs and outputs use human-readable values, NOT smallest chain units (wei, lamports, satoshi).

| โœ… Correct | โŒ Wrong |

|-----------|---------|

| --amount 0.1 (0.1 USDT) | --amount 100000000000000000 (100 quadrillion USDT!) |

| --amount 1 (1 SOL) | --amount 1000000000 (1 billion SOL!) |

This applies to: swap-quote, swap-calldata, swap-send, and all toAmount / fromAmount values in responses. The decimals field in responses is informational only โ€” do not use it for conversion.

Swap Flow: Command Sequence Matters

Swap is a multi-step process. These commands must be called in order:

1. swap-quote     โ†’ Get route and estimated output
2. swap-calldata  โ†’ Generate unsigned transaction data
3. (wallet signs the transaction externally)
4. swap-send      โ†’ Broadcast the signed transaction

Swap Quote: Reading the Response

Security Audit: Interpret Before Presenting

The security command returns raw audit data. Key fields to check:

| Field | Meaning | Action |

|-------|---------|--------|

| highRisk = true | Token has critical security issues | Warn user strongly. Do not recommend trading. |

| riskCount > 0 | Number of risk items found | List the specific risks to the user |

| warnCount > 0 | Number of warnings | Mention but less critical than risks |

| buyTax / sellTax > 0 | Token charges tax on trades | Include in cost estimation |

| isProxy = true | Contract is upgradeable | Mention โ€” owner can change contract behavior |

| cannotSellAll = true | Cannot sell 100% of holdings | Major red flag for meme coins |

Best practice: Run security before any swap involving an unfamiliar token. This should follow the user's configured security preference (see "First-Time Swap Configuration"). If set to "Always check" (default), run automatically and silently โ€” only surface results if risks are found. Never skip security checks for tokens the user has not traded before, regardless of preference.

K-line: Valid Parameters

Transaction Info: Valid Intervals

Historical Coins: Pagination

Native Tokens

Use empty string "" as the contract address for native tokens (ETH, SOL, BNB, etc.). This is a common source of errors โ€” do not pass the wrapped token address (e.g., WETH, WSOL) when querying native token info.

Common Stablecoin Addresses

Always use these verified addresses for USDT/USDC. Do not guess or generate contract addresses from memory โ€” incorrect addresses will cause API errors (error_code: 80000, "get token info failed").

USDT vs USDT0: Tether has begun migrating USDT to USDT0 (omnichain version via LayerZero) on some chains. On Arbitrum, the same contract address now represents USDT0 instead of legacy USDT. The contract addresses remain unchanged and work identically with the BGW API โ€” no special handling is needed. When a user asks to swap "USDT", use the address below regardless of whether the chain has migrated to USDT0.

| Chain (code) | USDT (USDT0) | USDC |

|-------------|------|------|

| Ethereum (eth) | 0xdAC17F958D2ee523a2206206994597C13D831ec7 | 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 |

| BNB Chain (bnb) | 0x55d398326f99059fF775485246999027B3197955 | 0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d |

| Base (base) | 0xfde4C96c8593536E31F229EA8f37b2ADa2699bb2 | 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 |

| Arbitrum (arbitrum) | 0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9 | 0xaf88d065e77c8cC2239327C5EDb3A432268e5831 |

| Optimism (optimism) | 0x94b008aA00579c1307B0EF2c499aD98a8ce58e58 | 0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85 |

| Polygon (matic) | 0xc2132D05D31c914a87C6611C10748AEb04B58e8F | 0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359 |

| Solana (sol) | Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB | EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v |

For other tokens, use token-info or a block explorer to verify the contract address before calling swap endpoints.

Using Market Data Effectively

The data commands (token-info, kline, tx-info, liquidity) are most useful when combined, not in isolation:

Pre-Trade Workflow

Before executing any swap, the agent should silently run risk checks and then present a single confirmation summary to the user. Do not prompt the user at every step.

Behind the scenes (agent runs automatically):

1. security     โ†’ Check highRisk, honeypot, tax
2. token-info   โ†’ Get current price, market cap, holder count
3. liquidity    โ†’ Check pool depth vs trade size
4. swap-quote   โ†’ Get route, expected output, slippage

If any red flags are found (highRisk, high tax, low liquidity, extreme slippage), stop and warn the user immediately with specifics.

If everything looks normal, present a single confirmation:

Swap Summary:
โ€ข 0.1 USDC โ†’ ~0.1000 USDT (BNB Chain)
โ€ข Route: bgwevmaggregator
โ€ข Slippage tolerance: 0.5%
โ€ข Price impact: ~0.07%
โ€ข Estimated gas: ~$0.05
โ€ข Token safety: โœ… No risks found
โ€ข Deadline: [user's configured preference, default 300s]

Proceed? [yes/no]

After user confirms:

5. swap-calldata โ†’ Generate unsigned transaction
6. (wallet signs the transaction)
7. swap-send    โ†’ Broadcast via MEV-protected endpoint

For well-known tokens (ETH, SOL, BNB, USDT, USDC, DAI, WBTC), the risk checks will almost always pass โ€” the single confirmation is sufficient. For unfamiliar or new tokens, be more verbose about the risks.

Order Mode: Cross-Chain + Gasless Swaps

The Order Mode API (order-* commands) is the recommended way to execute swaps. It supports everything the legacy swap-* flow does, plus:

When to use Order Mode vs Legacy Swap:

| Scenario | Use |

|----------|-----|

| Cross-chain swap | Order Mode (only option) |

| No native token for gas | Order Mode with no_gas |

| Same-chain swap | Either (Order Mode recommended) |

| Need order tracking/refunds | Order Mode |

Order Flow: 4-Step Process
1. order-quote   โ†’ Get price, recommended market, check no_gas support
2. order-create  โ†’ Create order, receive unsigned tx/signature data
3. (wallet signs the transaction or EIP-712 typed data)
4. order-submit  โ†’ Submit signed tx, get orderId confirmation
5. order-status  โ†’ Poll until status = success/failed/refunded
Order Quote Response

Key fields to check:

| Field | Meaning |

|-------|---------|

| toAmount | Estimated output (human-readable) |

| market | Required for order-create โ€” pass it exactly |

| slippage | Recommended slippage tolerance |

| priceImpact | Price impact percentage |

| fee.totalAmountInUsd | Total fee in USD |

| fee.appFee | Partner's fee portion |

| fee.platformFee | Platform fee portion |

| features: ["no_gas"] | If present, gasless mode is available |

| eip7702Bindend | Whether address has EIP-7702 binding |

Gasless Mode (no_gas)

Gasless mode uses EIP-7702 delegation โ€” a backend relayer constructs and pays for the transaction on your behalf. The gas cost is deducted from the input token amount.

  1. Call order-quote โ€” check if features contains "no_gas"
  2. Pass --feature no_gas to order-create
  3. Response returns signatures (not txs) โ€” EIP-712 + EIP-7702 auth
  4. Sign using API-provided hash fields, submit signatures
  5. Backend relayer constructs full EIP-7702 tx, pays gas, broadcasts
  6. No native token balance needed โ€” ideal for Agent wallets

Auto-detection logic:

Default: always use no_gas when available.

if order-quote returns features: ["no_gas"]:
    auto-apply --feature no_gas to order-create
elif user has no native token for gas:
    warn: "Insufficient gas. This route does not support gasless mode."
else:
    proceed without no_gas (normal tx mode)

โš ๏ธ Important: features in order-quote is not always reliable.

In testing, some routes return features: [] in the quote but still accept --feature no_gas in order-create. When the wallet has zero native token balance, always try no_gas regardless of the quote's features field. If order-create rejects it, fall back to informing the user they need gas.

Order Create Response: Two Modes

The response contains either txs (normal transaction) or signatures (EIP-7702 gasless):

Mode 1: Normal Transaction (txs)

{
  "orderId": "...",
  "txs": [{
    "kind": "transaction",
    "chainName": "base",
    "chainId": "8453",
    "data": {
      "to": "0x...",
      "calldata": "0x...",
      "gasLimit": "54526",
      "nonce": 308,
      "value": "0",
      "supportEIP1559": true,
      "maxFeePerGas": "...",
      "maxPriorityFeePerGas": "..."
    }
  }]
}

โ†’ Build transaction from data fields, sign with wallet, submit raw tx hex.

Mode 2: EIP-7702 Signature (signatures) โ€” Gasless

Returned when --feature no_gas is used. Contains 2 signatures to sign:

{
  "orderId": "...",
  "signatures": [
    {
      "kind": "signature",
      "chainName": "base",
      "chainId": "8453",
      "hash": "0x...",          // โ† Sign THIS hash directly
      "data": {
        "signType": "eip712",   // EIP-712: approve + swap bundled
        "types": { "Aggregator": [...], "Call": [...] },
        "domain": { "name": "BW7702Admin", "verifyingContract": "0x8C80e4d1..." },
        "message": {
          "calls": [
            { "target": "0x8335...", "callData": "0x095ea7b3..." },  // approve
            { "target": "0xBc1D...", "callData": "0xd984396a..." }   // swap
          ]
        }
      }
    },
    {
      "kind": "signature",
      "chainName": "base",
      "chainId": "8453",
      "hash": "0x...",          // โ† Sign THIS hash directly
      "data": {
        "signType": "eip7702_auth",   // EIP-7702: delegate to smart contract
        "contract": "0xa845C743...",   // delegation target
        "nonce": "0"
      }
    }
  ]
}

What each signature does:

  1. EIP-712 (Aggregator) โ€” authorizes the bundled calls (approve + swap) via the BW7702Admin contract
  2. EIP-7702 auth โ€” delegates your EOA to the EIP-7702 smart contract, enabling batched execution

โ†’ Sign each item's hash field with unsafe_sign_hash. Do NOT recompute hashes.

โ†’ Backend relayer receives signatures, constructs full EIP-7702 type-4 tx, pays gas, broadcasts.

Signing Order Responses

Critical: Use the API-provided hash field to sign. Do NOT recompute EIP-712 hashes yourself.

The encode_typed_data implementations in common libraries (eth-account, ethers.js) may produce different hashes for complex nested structs (Call[] with bytes callData). The API pre-computes the correct hash and returns it in each signature item's hash field.

Signing logic (for signatures mode โ€” gasless/EIP-7702):

from eth_account import Account

acct = Account.from_key(private_key)
signed_list = []
for sig_item in order_data["signatures"]:
    hash_bytes = bytes.fromhex(sig_item["hash"][2:])
    signed = acct.unsafe_sign_hash(hash_bytes)
    signed_list.append("0x" + signed.signature.hex())
# Submit: order-submit --order-id <id> --signed-txs <signed_list>

Signing logic (for txs mode โ€” normal gas):

for tx_item in order_data["txs"]:
    tx_dict = {
        "to": tx_item["data"]["to"],
        "data": tx_item["data"]["calldata"],
        "gas": int(tx_item["data"]["gasLimit"]),
        "nonce": int(tx_item["data"]["nonce"]),
        "chainId": int(tx_item["chainId"]),
        "gasPrice": int(tx_item["data"]["gasPrice"]),
        "value": <parse tx_item["data"]["value"]>,
    }
    signed_tx = acct.sign_transaction(tx_dict)
    signed_list.append("0x" + signed_tx.raw_transaction.hex())

Helper script: python3 scripts/order_sign.py --private-key <key> accepts order-create JSON from stdin and outputs signed hex array.

Backend flow after submit:

Agent signs โ†’ submits signatures โ†’ Backend relayer receives โ†’
Constructs full EIP-7702 tx (embeds our signatures) โ†’
Relayer pays gas โ†’ Broadcasts to chain

The Agent never constructs the full EIP-7702 transaction. The backend relayer handles tx construction, gas payment, and broadcasting. We only provide signatures.

Important notes:

EIP-7702 binding state affects signature count:

| State | eip7702Bindend | Signatures | What's signed |

|-------|-------------------|-----------|---------------|

| First gasless tx | false | 2 | EIP-712 (approve + swap) + EIP-7702 auth (delegation) |

| Subsequent gasless tx | true | 1 | EIP-712 (swap only, approve already done) |

The binding persists on-chain. Once bound, future gasless transactions on the same chain are faster (1 signature, ~5 seconds).

Order Status Lifecycle
init โ†’ processing โ†’ success
                  โ†’ failed
                  โ†’ refunding โ†’ refunded

| Status | Meaning | Action |

|--------|---------|--------|

| init | Order created, not yet submitted | Use toAmount for confirmation |

| processing | Transaction in progress | Poll, show "็ญ‰ๅพ…็กฎ่ฎค..." |

| success | Completed successfully | Show receiveAmount + txId + explorer link |

| failed | Transaction failed | Show error, suggest retry |

| refunding | Refund in progress | Wait, notify user |

| refunded | Funds returned | Show refund tx details |

order-status response fields (all statuses):

| Field | Description | Available |

|-------|-------------|-----------|

| orderId | Order identifier | Always |

| status | Current status | Always |

| fromChain / toChain | Source / destination chain | Always |

| fromContract / toContract | Token contracts | Always |

| fromAmount | Input amount | Always |

| toAmount | Estimated output (more accurate than quote) | Always (after create) |

| receiveAmount | Actual received amount | Only on success |

| txs | Array of {chain, txId, stage, tokens} | Only on success |

| createTime / updateTime | Unix timestamps | Always |

Polling strategy:

Known Issues & Pitfalls (Order Mode)
  1. Cross-chain minimum amount: Cross-chain swaps (e.g., Base USDC โ†’ BNB USDT) have a minimum of ~$2. Below that returns 80002 amount too low.
  1. features field unreliable for gasless: order-quote may return features: [] but order-create still accepts --feature no_gas. When wallet has zero native token, always try no_gas first.
  1. Base same-chain without no_gas: order-create on Base without --feature no_gas returns 80000 system error when the wallet has no ETH. This is because the API can't construct a normal tx for an account with no gas. Solution: use no_gas.
  1. EIP-712 hash mismatch: Do NOT use encode_typed_data from eth-account or similar libraries. Their encoding of nested Call[] with bytes callData differs from the API/contract implementation. Always sign the API-provided hash directly.
  1. Signature format: 65 bytes r + s + v where v is 27 or 28 (not y_parity 0/1). This is the standard output of unsafe_sign_hash.
  1. Order expiry: Orders have a deadline (typically 2 minutes from creation). Sign and submit promptly after order-create. If expired, create a new order.
  1. No approve needed for gasless: EIP-7702 gasless mode bundles approve + swap into one atomic operation via the Aggregator contract. No separate approve transaction needed.
  1. Never duplicate order execution: Signed and submitted orders are irreversible. Before creating a new order for the same trade, always check the previous order's status via order-status. If a previous script/process might still be running, verify it's truly dead before retrying. Creating and submitting two orders for the same trade will execute both and spend double the funds.
  1. Cross-chain orders return multiple TXs: A successful cross-chain order-status returns 2 entries in txs[] โ€” stage: "source" (origin chain) and stage: "target" (destination chain). Show both explorer links to the user.
  1. Cross-chain toAddress MUST use target chain's native address format: When swapping cross-chain, the toAddress must be a valid address on the destination chain, not the source chain. This applies to BOTH order-quote and order-create โ€” the quote will return 80000 without it for non-EVM targets.
Order Mode Error Codes

| Code | Meaning | Action |

|------|---------|--------|

| 80001 | Insufficient balance | Check balance, suggest smaller amount |

| 80002 | Amount too low | Increase amount |

| 80003 | Amount too high | Decrease amount |

| 80004 | Order expired | Re-create order |

| 80005 | Insufficient liquidity | Try different route or smaller amount |

| 80006 | Invalid request | Check parameters |

| 80007 | Signature mismatch | Re-sign with correct data |

Security Considerations (Order Mode)

Trust model: We sign hashes provided by the API. Verification layers:

| Layer | Verified | Method |

|-------|----------|--------|

| DOMAIN_SEPARATOR | โœ… | Matches on-chain contract 0x8C80e4d1... |

| AGGREGATOR_TYPE_HASH | โœ… | Found in contract bytecode |

| CALL_TYPE_HASH | โœ… | Found in contract bytecode |

| Message content | โœ… Readable | EIP-712 message.calls shows approve/swap targets & calldata |

| Hash correctness | โš ๏ธ Trusted | Cannot independently recompute due to encoding differences |

| Response integrity | โš ๏ธ TLS only | No server-side signature on response (enhancement pending) |

Pre-sign verification checklist:

  1. Read message.calls โ€” verify targets are known contracts (router, token)
  2. Verify message.msgSender matches your wallet address
  3. Verify domain.verifyingContract is the known BW7702Admin contract
  4. Verify domain.chainId matches expected chain
  5. After completion, verify on-chain tx matches expected token transfer

Planned enhancement: API response signing with server public key for MITM protection.

Supported Chains (Order Mode)

| Chain | Code | Same-chain | Cross-chain |

|-------|------|-----------|-------------|

| Ethereum | eth | โœ… | โœ… |

| Solana | sol | โœ… | โŒ (to-sol bug) |

| BNB Chain | bnb | โœ… | โœ… |

| Base | base | โœ… | โœ… |

| Arbitrum | arbitrum | โœ… | โœ… |

| Polygon | matic | โœ… | โœ… |

| Morph | morph | โœ… | โœ… |

Pre-Trade Workflow (Order Mode)

Key principle: order-create before present, present before sign.

The order is a contract โ€” the user sees the actual order details, confirms, THEN the agent signs and submits. The agent MUST NOT sign or submit without explicit user confirmation.

1. security       โ†’ Check token safety (automatic, silent unless issues found)
2. order-quote    โ†’ Get price, market, check no_gas + eip7702Bindend
3. order-create   โ†’ Create order (auto-apply no_gas if available)
                     Returns orderId + unsigned tx/signature data
4. order-status   โ†’ Get order details (toAmount is more accurate than quote)
5. PRESENT        โ†’ Show confirmation summary to user (MANDATORY)
                     Use toAmount from order-status, NOT from quote
                     Include: order ID, amounts, fees, gas mode, signatures, safety
                     Include: EIP-712 verification (domain, msgSender, calls)
                     Include: small amount gasless warning if < $1
6. WAIT           โ†’ User must explicitly say "yes" / "confirm" / "ๆ‰ง่กŒ"
                     If user says "no" โ†’ abort, do not sign
7. Sign + Submit  โ†’ Sign using API-provided hash fields, then order-submit
8. Poll once      โ†’ Wait 10s, then order-status once
                     If success โ†’ show receiveAmount + txId + explorer link
                     If still processing โ†’ show order ID + status, tell user to check later
                     DO NOT loop/block waiting for completion โ€” return control to user immediately

Why this order matters:

Completion message (same-chain):

โœ… Swap Complete
โ€ข Order: f347d76e...
โ€ข 1 USDC โ†’ 0.98382 USDT (Base)
โ€ข Gas mode: Gasless
โ€ข Tx: 0x786eff3d...
โ€ข Explorer: https://basescan.org/tx/0x786eff3d...

Completion message (cross-chain):

โœ… Swap Complete
โ€ข Order: 861d8427...
โ€ข 2 USDC (Base) โ†’ 1.877485 USDT (Polygon)
โ€ข Gas mode: Gasless
โ€ข Source TX (Base): 0x2954bb0d...
  https://basescan.org/tx/0x2954bb0d...
โ€ข Target TX (Polygon): 0xd72483c8...
  https://polygonscan.com/tx/0xd72483c8...

If failed:

โŒ Swap Failed
โ€ข Order: f365ba3d...
โ€ข 0.1 USDC โ†’ USDT (Base)
โ€ข Status: failed
โ€ข Possible causes: relayer error, insufficient liquidity, expired

Block explorer URLs by chain:

| Chain | Explorer URL |

|-------|-------------|

| eth | https://etherscan.io/tx/{txId} |

| bnb | https://bscscan.com/tx/{txId} |

| base | https://basescan.org/tx/{txId} |

| arbitrum | https://arbiscan.io/tx/{txId} |

| matic | https://polygonscan.com/tx/{txId} |

| optimism | https://optimistic.etherscan.io/tx/{txId} |

| sol | https://solscan.io/tx/{txId} |

| trx | https://tronscan.org/#/transaction/{txId} |

Poll timing: ONE poll only.

Gas mode strategy: ALWAYS try gasless first.

1. Always pass --feature no_gas to order-create (regardless of quote features field)
2. Check response:
   a. Returns `signatures` array โ†’ Gasless โœ… proceed with EIP-712 signing
   b. Returns `txs` array (normal transactions) โ†’ Gasless NOT supported on this chain
      โ†’ Warn user: "โš ๏ธ This chain does not support gasless. Need native token for gas."
      โ†’ Check if wallet has native token balance
      โ†’ If no balance: "โŒ Cannot execute: no [MATIC/ETH/...] for gas and gasless unavailable"
      โ†’ If has balance: proceed with normal tx signing, show "Gas mode: Normal"

Why always try gasless:

Gasless support by chain (as of 2026-03-04):

| Chain | Gasless (EIP-7702) | Notes |

|-------|-------------------|-------|

| Base | โœ… Supported | Tested, confirmed |

| Ethereum | โœ… Supported | โ€” |

| BNB Chain | โœ… Supported | โ€” |

| Polygon | โœ… Supported | Same-chain confirmed; cross-chain requires 7702 binding first |

| Arbitrum | โœ… Supported | โ€” |

| Morph | โœ… Supported | โ€” |

| Solana | โŒ Not working | Order mode gasless submit succeeds but execution always fails; pending API team fix |

โš ๏ธ Cross-chain gasless requires source chain 7702 binding. If the wallet has never done a gasless transaction on the source chain, the first cross-chain order will fall back to normal txs. Do a same-chain gasless swap first to bind 7702, then cross-chain gasless will work.

Always try gasless first rather than relying on this table.

User override: If the user explicitly says to use their own gas (e.g., "use my gas", "user gas", "ไธ่ฆ gasless", "็”จ่‡ชๅทฑ็š„ gas"), do NOT pass --feature no_gas to order-create. The order will use normal gas mode instead, and gas is paid from the wallet's native token balance. Show "Gas mode: User Gas (native token)" in the confirmation summary.

toAmount: Three Sources of Truth

| Source | Field | When Available | Accuracy |

|--------|-------|---------------|----------|

| order-quote | toAmount | Before create | Rough estimate, pre-gas |

| order-status (init) | toAmount | After create, before submit | Better estimate โ€” use this for confirmation |

| order-status (success) | receiveAmount | After completion | Actual received amount |

Always use order-status.toAmount for the confirmation summary, not the quote's toAmount. The order-status value is calculated after actual routing and is more accurate.

Gas Mode: Default to Gasless

Always default to gasless โ€” pass --feature no_gas to order-create on every trade. Do not check features field first, do not ask the user to choose.

How to detect gasless success vs fallback:

Rationale: Gasless mode eliminates the need for users/agents to maintain native token balances on every chain. The gas cost is minimal compared to convenience. Trying gasless has zero cost โ€” if the chain doesn't support it, the API silently falls back to normal txs.

โš ๏ธ MANDATORY: The agent MUST present the confirmation summary and wait for explicit user approval before signing and submitting. Never skip this step. No exceptions.

Confirmation summary (gasless, same-chain):

Order Created โœ…
โ€ข Order: f347d76e4b7e434897c2c699b7a588b9
โ€ข 0.1 USDC โ†’ ~0.086 USDT (Base)
โ€ข โš ๏ธ Gasless: gas ไปŽ่พ“ๅ…ฅ้‡‘้ขๆ‰ฃ้™ค๏ผŒๅฐ้ขไบคๆ˜“ gas ๅ ๆฏ”่พƒ้ซ˜
โ€ข Route: bgwevmaggregator
โ€ข Price impact: 0.009%
โ€ข Fees: $0.0003 (app fee)
โ€ข Gas mode: Gasless โœ… (EIP-7702 ๅทฒ็ป‘ๅฎš)
โ€ข Signatures to sign: 1 (EIP-712)
โ€ข Token safety: โœ… Both verified

EIP-712 Verification:
โ€ข domain: BW7702Admin @ 0x8C80e4d1... โœ…
โ€ข msgSender: matches our wallet โœ…
โ€ข calls: 1 (swap via router 0xBc1D9760...)

Confirm and sign? [yes/no]

Cross-chain gasless example:

Order Created โœ…
โ€ข Order: 9c3f5bcab4a2449ea5e66a9770ea7169
โ€ข 2 USDC (Base) โ†’ ~1.94 USDT (Polygon)
โ€ข โš ๏ธ Gasless: gas ไปŽ่พ“ๅ…ฅ้‡‘้ขๆ‰ฃ้™ค
โ€ข Route: bkbridgev3.liqbridge (cross-chain bridge)
โ€ข Price impact: 0.024%
โ€ข Fees: $0.014 (app $0.006 + platform $0.006 + gas $0.002)
โ€ข Gas mode: Gasless โœ… (EIP-7702 ๅทฒ็ป‘ๅฎš)
โ€ข Signatures to sign: 1 (EIP-712)
โ€ข Token safety: โœ… Both verified

Confirm and sign? [yes/no]

Normal gas example:

Order Created โœ…
โ€ข Order: a1b2c3d4e5f6...
โ€ข 2.0 USDC (Base) โ†’ ~1.95 USDT (BNB Chain)
โ€ข Route: bkbridgev3.liqbridge
โ€ข Price impact: 0.057%
โ€ข Fees: $0.114 total
โ€ข Gas mode: Normal (native token)
โ€ข Transactions to sign: 1
โ€ข Token safety: โœ… Both verified

Confirm and sign? [yes/no]

โš ๏ธ toAmount in confirmation uses order-status (init), not quote. This is more accurate because it reflects actual routing. However, gasless gas deduction may still reduce the final receiveAmount further.

Confirmation summary MUST include:

  1. Order ID
  2. Input โ†’ output with ~ estimate
  3. Route and price impact
  4. Fees breakdown
  5. Gas mode (Gasless/Normal/User Gas)
  6. Number and type of signatures
  7. Small amount warning if applicable
  8. Token safety status
  9. EIP-712 verification (domain, msgSender, calls summary)

Gas mode display rules:

Small amount gasless warning:

When input amount < $1 USD, show warning: gasless gas cost is fixed (~$0.01-0.02) regardless of trade size. For small trades this can be 10-15% of the input. For amounts > $10 the gas overhead is < 0.2% and negligible.

| Input Amount | Estimated Gas Overhead |

|-------------|----------------------|

| $0.10 | ~15% โš ๏ธ |

| $1.00 | ~1.5% |

| $10.00 | ~0.15% |

| $100.00 | ~0.015% |

Wallet & Signing Domain Knowledge

Key Hierarchy (BIP-39 / BIP-44)
Mnemonic (12/24 words)
  โ””โ†’ Seed (512 bits via PBKDF2)
      โ””โ†’ Master Key
          โ””โ†’ Derivation Path (BIP-44)
              โ”œโ†’ m/44'/60'/0'/0/0   โ†’ EVM private key โ†’ ETH/BNB/Base/Arbitrum/Polygon address
              โ”œโ†’ m/44'/60'/0'/0/1   โ†’ EVM account #2
              โ”œโ†’ m/44'/501'/0'/0'   โ†’ Solana private key (Ed25519)
              โ””โ†’ m/44'/195'/0'/0/0  โ†’ Tron private key

Critical facts:

Key Management for Agents

Principle: minimal privilege, no persistence.

Storage:     1Password only (never local files, env vars, or code)
Injection:   Fetch โ†’ use โ†’ destroy in same script execution
Scope:       Single private key, not full mnemonic
Derivation:  Done once during setup, only the derived key is stored

Why agents hold a private key, not a mnemonic:

Key retrieval pattern (Python):

# Fetch from 1Password, use, discard
import subprocess
key = subprocess.run(
    ["python3.13", "scripts/op_sdk.py", "get", "Agent Wallet", "--field", "evm_key", "--reveal"],
    capture_output=True, text=True
).stdout.strip()
# ... use key for signing ...
del key  # explicit cleanup
Signature Types (EVM)

| Type | Use Case | How to Sign |

|------|----------|-------------|

| Raw Transaction (type 0/2) | Normal transfers, swaps | Account.sign_transaction(tx_dict) โ†’ full signed tx hex |

| EIP-191 (personal_sign) | Message signing, off-chain auth | Account.sign_message(encode_defunct(msg)) |

| EIP-712 (typed data) | Structured data (permits, orders) | Account.sign_message(encode_typed_data(...)) or unsafe_sign_hash(hash) |

| EIP-7702 (delegation auth) | Delegate EOA to smart contract | unsafe_sign_hash(keccak(0x05 \|\| rlp([chainId, addr, nonce]))) |

When to use which:

โš ๏ธ unsafe_sign_hash vs sign_message:

Multi-Chain Signing

| Chain Family | Curve | Signing Library | Address Format |

|-------------|-------|----------------|----------------|

| EVM (ETH/BNB/Base/...) | secp256k1 | eth-account | 0x... (20 bytes, checksummed) |

| Solana | Ed25519 | solders / solana-py | Base58 (32 bytes) |

| Tron | secp256k1 | Same as EVM, Base58Check address | T... |

EVM all-chain: Sign once, broadcast to any EVM chain. The chainId in the tx prevents replay across chains.

Transaction Anatomy (EVM)
Type 0 (Legacy):     {nonce, gasPrice, gasLimit, to, value, data}
Type 2 (EIP-1559):   {nonce, maxFeePerGas, maxPriorityFeePerGas, gasLimit, to, value, data, chainId}
Type 4 (EIP-7702):   {... + authorizationList: [{chainId, address, nonce, y_parity, r, s}]}

Key fields for swap transactions:

EVM Token Approval (Critical)

On EVM chains (Ethereum, BNB Chain, Base, Arbitrum, Optimism), tokens require an approve transaction before the router contract can spend them. Without approval, the swap transaction will fail on-chain and still consume gas fees.

Include the approval status in the confirmation summary when relevant:

โ€ข Token approval: โš ๏ธ USDC not yet approved for router (one-time gas ~$0.03)

Identifying Risky Tokens

Combine multiple signals to assess token risk. No single indicator is definitive:

| Signal | Source | Red Flag |

|--------|--------|----------|

| highRisk = true | security | Critical โ€” do not trade |

| cannotSellAll = true | security | Honeypot-like behavior |

| buyTax or sellTax > 5% | security | Hidden cost, likely scam |

| isProxy = true | security | Owner can change rules anytime |

| Holder count < 100 | token-info | Extremely early or abandoned |

| Single holder > 50% supply | token-info | Rug pull risk |

| LP lock = 0% | liquidity | Creator can pull all liquidity |

| Pool liquidity < $10K | liquidity | Any trade will cause massive slippage |

| Very high 5m volume, near-zero 24h volume | tx-info | Likely wash trading |

| Token age < 24h | token-info | Unproven, higher risk |

When multiple red flags appear together, strongly advise the user against trading.

Slippage Control

Important: distinguish between slippage tolerance and actual price impact. These are different things:

Slippage tolerance (auto-calculated by BGW):

The swap-quote response includes a slippage field (e.g., "0.5" = 0.5%). This is the system's recommended tolerance, auto-calculated based on token volatility and liquidity.

In swap-calldata, you can override it:

Slippage tolerance thresholds:

| Tolerance | Action |

|-----------|--------|

| โ‰ค 1% | Normal for major pairs. Show in summary. |

| 1-3% | Acceptable for mid-cap tokens. Include in summary. |

| 3-10% | Warn user. Suggest reducing trade size or setting a custom lower value. |

| > 10% | Strongly warn. Low liquidity or high volatility. Suggest splitting into smaller trades. |

| > 0.5% for stablecoin pairs | Abnormal. Flag to user โ€” stablecoin swaps should have minimal slippage. |

Price impact (calculated by agent):

  1. Get market price from token-info
  2. Get quote price from swap-quote (= toAmount / fromAmount)
  3. Price impact โ‰ˆ (market_price - quote_price) / market_price ร— 100%

Price impact > 3% means the trade size is too large relative to available liquidity. The liquidity command can confirm โ€” if trade amount > 2% of pool size, expect significant impact.

Gas and Fees

Transaction costs vary by chain. Be aware of these when presenting swap quotes:

| Chain | Typical Gas | Notes |

|-------|------------|-------|

| Solana | ~$0.001-0.01 | Very cheap, rarely a concern |

| BNB Chain | ~$0.05-0.30 | Low, but check during congestion |

| Ethereum | ~$1-50+ | Highly variable. Small trades (<$100) may not be worth the gas. |

| Base / Arbitrum / Optimism | ~$0.01-0.50 | L2s are cheap but not free |

Important considerations:

Broadcasting with swap-send (Complete CLI Flow)

The swap-send command broadcasts a signed raw transaction via BGW's MEV-protected endpoint. This is the final step in the swap flow.

Command format:

python3 scripts/bitget_api.py swap-send --chain <chain> --txs "<id>:<chain>:<from_address>:<signed_raw_tx>"

Parameter breakdown:

Complete swap flow using only CLI commands:

# Step 1: Get quote
python3 scripts/bitget_api.py swap-quote \
  --from-chain bnb --from-contract 0x55d398326f99059fF775485246999027B3197955 \
  --to-contract 0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d \
  --amount 0.1

# Step 2: Get calldata (use market value from step 1 response)
python3 scripts/bitget_api.py swap-calldata \
  --from-chain bnb --from-contract 0x55d398326f99059fF775485246999027B3197955 \
  --to-contract 0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d \
  --amount 0.1 --from-address <wallet> --to-address <wallet> \
  --market bgwevmaggregator

# Step 3: Sign the calldata externally (wallet app, web3.py, etc.)
# This produces a signed raw transaction hex

# Step 4: Broadcast
python3 scripts/bitget_api.py swap-send --chain bnb \
  --txs "tx1:bnb:<wallet_address>:<signed_raw_tx_hex>"

Key points:

Common Pitfalls

  1. Wrong chain code: Use sol not solana, bnb not bsc. See the Chain Identifiers table below.
  2. Batch endpoints format: batch-token-info uses --tokens "sol:<addr1>,eth:<addr2>" โ€” chain and address are colon-separated, pairs are comma-separated.
  3. Liquidity pools: The liquidity command returns pool info including LP lock percentage. 100% locked LP is generally a positive signal; 0% means the creator can pull liquidity.
  4. Stale quotes: If more than ~30 seconds pass between getting a quote and executing, prices may have moved. Re-quote for time-sensitive trades.
  5. Insufficient gas: A swap can fail silently if the wallet lacks native tokens for gas. The transaction still consumes gas fees even when it reverts. Check balance before proceeding.
  6. Missing token approval (EVM): On EVM chains, forgetting to approve the token for the router is the #1 cause of failed swaps. The transaction will revert on-chain and waste gas. See "EVM Token Approval" section above.
  7. Automate the boring parts: Run security/liquidity/quote checks silently. Only surface results to the user in the final confirmation summary unless something is wrong.

Scripts

All scripts are in scripts/ and use Python 3.11+. No external credential setup needed โ€” demo API keys are built in.

`scripts/bitget_api.py` โ€” Unified API Client

# Token info (price, supply, holders, socials)
python3 scripts/bitget_api.py token-info --chain sol --contract <address>

# Token price only
python3 scripts/bitget_api.py token-price --chain sol --contract <address>

# Batch token info (comma-separated)
python3 scripts/bitget_api.py batch-token-info --tokens "sol:<addr1>,eth:<addr2>"

# K-line data
python3 scripts/bitget_api.py kline --chain sol --contract <address> --period 1h --size 24

# Token transaction info (5m/1h/4h/24h volume, buyers, sellers)
python3 scripts/bitget_api.py tx-info --chain sol --contract <address>

# Batch transaction info
python3 scripts/bitget_api.py batch-tx-info --tokens "sol:<addr1>,eth:<addr2>"

# Token rankings (topGainers / topLosers)
python3 scripts/bitget_api.py rankings --name topGainers

# Token liquidity pools
python3 scripts/bitget_api.py liquidity --chain sol --contract <address>

# Historical coins (discover new tokens)
python3 scripts/bitget_api.py historical-coins --create-time <datetime> --limit 20

# Security audit
python3 scripts/bitget_api.py security --chain sol --contract <address>

# Swap quote (amount is human-readable)
python3 scripts/bitget_api.py swap-quote --from-chain sol --from-contract <addr> --to-contract <addr> --amount 1

# Swap calldata (returns tx data for signing; --slippage is optional, system auto-calculates if omitted)
python3 scripts/bitget_api.py swap-calldata --from-chain sol --from-contract <addr> --to-contract <addr> --amount 1 --from-address <wallet> --to-address <wallet> --market <market> --slippage 2

# Swap send (broadcast signed transaction)
python3 scripts/bitget_api.py swap-send --chain sol --raw-transaction <signed_hex>

# --- Order Mode (cross-chain + gasless) ---

# Order quote (supports cross-chain: fromChain != toChain)
python3 scripts/bitget_api.py order-quote \
  --from-chain base --from-contract 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 \
  --to-chain bnb --to-contract 0x55d398326f99059fF775485246999027B3197955 \
  --amount 2.0 --from-address <wallet>

# Order create (returns unsigned tx data; use --feature no_gas for gasless)
python3 scripts/bitget_api.py order-create \
  --from-chain base --from-contract 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 \
  --to-chain bnb --to-contract 0x55d398326f99059fF775485246999027B3197955 \
  --amount 2.0 --from-address <wallet> --to-address <wallet> \
  --market bkbridgev3.liqbridge --slippage 3.0 --feature no_gas

# Order submit (submit signed transaction)
python3 scripts/bitget_api.py order-submit \
  --order-id <orderId> --signed-txs "0x<signed_hex>"

# Order status (poll order completion)
python3 scripts/bitget_api.py order-status --order-id <orderId>

Chain Identifiers

| Chain | ID | Code |

|-------|------|------|

| Ethereum | 1 | eth |

| Solana | 100278 | sol |

| BNB Chain | 56 | bnb |

| Base | 8453 | base |

| Arbitrum | 42161 | arbitrum |

| Tron | 6 | trx |

| Ton | 100280 | ton |

| Sui | 100281 | suinet |

| Optimism | 10 | optimism |

| Polygon | 137 | matic |

Use empty string "" for native tokens (ETH, SOL, BNB, etc.).

Safety Rules

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.