gmgn-swap
Original:🇺🇸 English
Translated
Submit a GMGN token swap or query order status. Requires private key configured. Supports sol / bsc / base.
10installs
Sourcegmgnai/gmgn-skills
Added on
NPX Install
npx skill4agent add gmgnai/gmgn-skills gmgn-swapTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Use the tool to submit a token swap or query an existing order. Requires private key ( in ).
gmgn-cliGMGN_PRIVATE_KEY.envSub-commands
| Sub-command | Description |
|---|---|
| Submit a token swap |
| Query order status |
Supported Chains
solbscbaseChain Currencies
Currency tokens are the base/native assets of each chain. They are used to buy other tokens or receive proceeds from selling. Knowing which tokens are currencies is critical for usage (see Swap Parameters below).
--percent| Chain | Currency tokens |
|---|---|
| SOL (native, So11111111111111111111111111111111111111112), USDC ( |
| BNB (native, 0x0000000000000000000000000000000000000000), USDC ( |
| ETH (native, 0x0000000000000000000000000000000000000000), USDC ( |
Prerequisites
Both and must be set in . The private key must correspond to the wallet bound to the API Key.
GMGN_API_KEYGMGN_PRIVATE_KEY.envSwap Usage
bash
# Basic swap
npx gmgn-cli swap \
--chain sol \
--from <wallet_address> \
--input-token <input_token_address> \
--output-token <output_token_address> \
--amount <input_amount_smallest_unit>
# With slippage
npx gmgn-cli swap \
--chain sol \
--from <wallet_address> \
--input-token <input_token_address> \
--output-token <output_token_address> \
--amount 1000000 \
--slippage 0.01
# With anti-MEV (SOL)
npx gmgn-cli swap \
--chain sol \
--from <wallet_address> \
--input-token <input_token_address> \
--output-token <output_token_address> \
--amount 1000000 \
--anti-mev
# Sell 50% of a token (input_token must NOT be a currency)
npx gmgn-cli swap \
--chain sol \
--from <wallet_address> \
--input-token <token_address> \
--output-token <sol_or_usdc_address> \
--percent 50Order Query
bash
npx gmgn-cli order get --chain sol --order-id <order_id>Swap Parameters
| Parameter | Required | Description |
|---|---|---|
| Yes | |
| Yes | Wallet address (must match API Key binding) |
| Yes | Input token contract address |
| Yes | Output token contract address |
| No* | Input amount in smallest unit. Required unless |
| No* | Sell percentage of |
| No | Slippage tolerance, e.g. |
| No | Minimum output amount |
| No | Enable anti-MEV protection (default true) |
| No | Priority fee in SOL (≥ 0.00001, SOL only) |
| No | Tip fee (SOL ≥ 0.00001 / BSC ≥ 0.000001 BNB) |
| No | Max automatic fee cap |
| No | Gas price in gwei (BSC ≥ 0.05 / BASE/ETH ≥ 0.01) |
| No | EIP-1559 max fee per gas (Base only) |
| No | EIP-1559 max priority fee per gas (Base only) |
Swap Response Fields
| Field | Type | Description |
|---|---|---|
| string | Order ID for follow-up queries |
| string | Transaction hash |
| int | Order state code |
| string | |
| string | Confirmation detail message |
| string | Error code on failure |
| string | Error description on failure |
| number | Block height of the transaction |
| number | Block height when the order was placed |
| string | Input token contract address |
| string | Output token contract address |
| string | Actual input consumed (smallest unit); empty if not filled |
| string | Actual output received (smallest unit); empty if not filled |
Notes
- Swap uses critical auth (API Key + signature) — CLI handles signing automatically, no manual processing needed
- After submitting a swap, use to poll for confirmation
order get - is in the smallest unit (e.g., lamports for SOL)
--amount - Use to get single-line JSON for further processing
--raw
Execution Guidelines
-
Currency resolution — When the user names a currency (SOL/BNB/ETH/USDC) instead of providing an address, look up its address in the Chain Currencies table and apply it automatically — never ask the user for it.
- Buy ("buy X SOL of TOKEN", "spend 0.5 USDC on TOKEN") → resolve currency to
--input-token - Sell ("sell TOKEN for SOL", "sell 50% of TOKEN to USDC") → resolve currency to
--output-token
- Buy ("buy X SOL of TOKEN", "spend 0.5 USDC on TOKEN") → resolve currency to
-
Pre-trade confirmation — Before executing, always present the key parameters (chain, from, input-token, output-token, amount or percent) to the user and ask for explicit confirmation.
swap -
Percentage sell restriction —is ONLY valid when
--percentis NOT a currency. Do NOT useinput_tokenwhen--percentis SOL/BNB/ETH (native) or USDC. This includes: "sell 50% of my SOL", "use 30% of my BNB to buy X", "spend 50% of my USDC on X" — all unsupported. Explain the restriction to the user and ask for an explicit absolute amount instead.input_token -
Chain-wallet compatibility — SOL addresses are incompatible with EVM chains (bsc/base). Warn the user and abort if the address format does not match the chain.
-
Credential sensitivity —and
GMGN_API_KEYcan directly execute trades on the linked wallet. Never log, display, or expose these values.GMGN_PRIVATE_KEY -
Order polling — After a swap, ifis not yet
confirmation.state/confirmed/failed, poll withexpiredup to 3 times at 5-second intervals before reporting a timeout. Once confirmed, display the trade result usingorder getandfilled_input_amount(convert from smallest unit using token decimals), e.g. "Spent 0.1 SOL → received 98.5 USDC" or "Sold 1000 TOKEN → received 0.08 SOL".filled_output_amount -
Block explorer links — After a successful swap, display a clickable explorer link for the returned:
hashChain Explorer sol https://solscan.io/tx/<hash>bsc https://bscscan.com/tx/<hash>base https://basescan.org/tx/<hash>eth https://etherscan.io/tx/<hash>