> Treat every fee rate, margin ratio, order limit, minimum, price, amount and deposit address in this documentation as an illustration of the shape of the value, never as a constant to hardcode - for perps the live values are served by GET /markets and GET /config on the Perps API, for swaps by GET /quote and GET /swap on the DEX Aggregator API. Contract addresses on the Smart Contracts page and in the Agent Swap Guide router table are the deployed ones: send swaps only to the tx.router returned by GET /swap, after checking it is listed there.

# Agent Swap Guide

> Let an AI agent swap tokens for you on HyperEVM or Elysium. It quotes, checks and simulates every trade; you sign.

Let an AI agent — Claude Code, Cursor, or your own — swap tokens for you on HyperEVM or Elysium. You ask in plain words ("swap 1 HYPE to USDC on Elysium"); the agent gets the best route from HyperFlow, checks it, and hands you the transaction to sign.

The first part of this page is for you: what the agent does and never does. The rest is the set of rules the agent follows, in whatever language or tools it uses. The same rules apply if you are writing a bot or app on the [DEX Aggregator API](/developers/dex-aggregator) yourself.

## What the agent does

#### Finds the tokens

Reads each token's name and decimals on-chain and shows them to you, so you confirm it is the right token. It never guesses an address.

#### Gets a quote

Asks HyperFlow for the best route and shows what you pay, what you receive, the minimum you will receive, and any fee. The minimum you confirm is written into the transaction, so you never get less.

#### Checks the price

Warns you if the trade itself moves the price against you by more than 1% (price impact), and asks again above 5%.

#### Asks you to approve the token, if needed

For tokens other than HYPE, asks you to approve — a one-time permission letting HyperFlow's router move exactly the amount being swapped, never an unlimited amount.

#### Simulates the swap

Dry-runs the transaction on the chain first. If the dry run fails, nothing is sent.

#### You sign, it confirms

You sign in your own wallet, on the chain the agent names; the agent then checks the result and gives you the explorer link.

## What it never does

* Ask for, read or store your private key, seed phrase or keystore password.
* Send any transaction without your confirmation.
* Send a swap to a contract other than HyperFlow's routers listed on this page. An approval goes to the token itself, and only for one of those routers.

## Example

> **You:** Swap 1 HYPE to USDC on Elysium.
>
> **Agent:** Which USDC? Please paste its address or explorer link on Elysium.
>
> **You:** 0xb47c4c8f73f009cc0c0d3f92b388d13e293f0b65
>
> **Agent:** That is USDC, 6 decimals. You pay 1 HYPE (about 59 USD) and receive about 59.08 USDC, at least 58.79 USDC with 0.5% slippage. Price impact is under 0.1% and the dry run succeeded. Here is the transaction — check your wallet is on Elysium (chain ID 99901) before signing.

## Use it

Paste this to any agent that can read web pages — Claude, ChatGPT, Cursor:

```text
Read https://docs.hyperflow.fun/developers/agent-swap-guide.md and follow it to swap 1 HYPE to USDC on Elysium.
```

To keep it as a Claude Code skill, so Claude uses it whenever you ask for a swap:

```bash
mkdir -p ~/.claude/skills/hyperflow-swap && cd ~/.claude/skills/hyperflow-swap
printf -- '---\nname: hyperflow-swap\ndescription: Swap tokens on HyperEVM or Elysium through HyperFlow\n---\n' > SKILL.md
curl -fsSL https://docs.hyperflow.fun/developers/agent-swap-guide.md >> SKILL.md
```

Run it again to pick up changes to this page.

## Agent instructions

> **Note**
>
> Everything below is written for the agent. Follow every rule; when a check fails, stop and tell the user rather than working around it.

### Chains

| Chain    | API base URL                               | Chain ID | Public RPC                        | Explorer                      |
| -------- | ------------------------------------------ | -------- | --------------------------------- | ----------------------------- |
| HyperEVM | `https://ag-api.hyperflow.fun/v1/hyperevm` | `999`    | `https://rpc.hyperliquid.xyz/evm` | `https://hyperevmscan.io`     |
| Elysium  | `https://ag-api.hyperflow.fun/v1/elysium`  | `99901`  | `https://rpc.elysium.kinetiq.xyz` | `https://elysium.kinetiq.xyz` |

Routers — the only contracts a swap may be sent to:

| Chain    | Standard router                              | Router for swaps with an integrator fee      |
| -------- | -------------------------------------------- | -------------------------------------------- |
| HyperEVM | `0x980B9271A33c4B31214301fAE584B18dBB9731eC` | `0x0FbE14a7Cd24aDB08575d67bd39d2290A12126b0` |
| Elysium  | `0x980B9271A33c4B31214301fAE584B18dBB9731eC` | `0x995E574059e1dD9528C22627773A397Bbb073A22` |

The native gas token (HYPE on both chains) is `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE`, with 18 decimals.

### Before you quote

1. **Pick one chain and keep it.** Use that chain's API base URL, RPC and router list for every step. Check the RPC's chain ID matches before any on-chain read.
2. **Never guess a token address.** Use an address the user gave, or ask for a link to the token on the chain's explorer. There is no token-search endpoint.
3. **Read each ERC-20 token's `symbol()` and `decimals()` on-chain** and show the symbol to the user. Skip this for the native token (18 decimals).
4. **If a read fails, stop.** "No code at address" means it is not a token on this chain — ask the user. A rate-limit or timeout error means retry after a few seconds. Never continue with a missing or default decimals value: a wrong value scales the amount by powers of ten.
5. **Convert the amount to wei with the token's decimals**, then convert it back and show the user, since extra decimal places are cut off.
6. **Slippage is a fraction:** `0.005` means 0.5%, `0.5` means 50%. Use at most `0.05` unless the user explicitly agrees to more. If the user gives a number without a % sign, ask what they mean. The API applies values above 0 and up to `0.5`; anything else silently becomes `0.01` — after the quote, check `minAmountOut` is about `amountOut × (1 − slippage)` and tell the user if the default was used.

### Quote

7. **Call `GET /quote`** with `tokenIn`, `tokenOut`, `amountIn` (wei) and `slippage`. If you integrate for a wallet or app that charges its own fee, add `feeBps` (1–100) and `feeReceiver` — see [Integrator fee](/developers/dex-aggregator#integrator-fee).
8. **Treat any non-200 status, `error` or `errors` in the body as a failure** — see [API errors](#api-errors). Set a timeout on every request. Token symbols are not accepted; the API needs addresses.
9. **Show the user, in token units:** what they pay, what they receive (`amountOut`), the minimum they will receive (`minAmountOut`), the USD value of both sides, and the integrator fee if any. Both `amountOut` and `minAmountOut` are already net of that fee.
10. **Check price impact.** `priceImpactPercent` is in percent, excludes the integrator fee, and is negative when the route loses value. Below −1, warn the user. Below −5, say plainly the trade loses more than 5% and suggest a smaller amount; continue only if the user confirms again. Zero or positive values need no warning.
11. **Get the user's confirmation and remember the `minAmountOut` they confirmed.**

### Build the transaction

12. **Call `GET /swap`** with the same parameters plus:
    * `receiver`: the user's address, which must be the address that will sign;
    * `minAmountOut`: the value the user confirmed, so the transaction can never pay less;
    * `deadline`: now + 120 seconds (Unix seconds), so a transaction signed late fails instead of filling at a stale price.
13. **Check the router.** `tx.router` must be in this chain's row of the router table, ignoring case: the standard router when you sent no `feeBps`, the integrator-fee router when you did. With a fee, `quote.integratorFee.bps` and `.receiver` must equal what you sent; without one, `integratorFee` must be absent. If anything differs, stop.
14. **If `/swap` returns `400` `minAmountOut is above the quoted output less slippage`**, the price moved against the user: quote again, show the new amounts and get confirmation again.
15. **If the user has not signed before the deadline**, call `/swap` again and repeat checks 13 and 14.

### Approve (ERC-20 input only)

16. **Read the user's `allowance` for `tx.router`.** If the read fails, retry; never treat a failed read as enough allowance.
17. **If it is below `amountIn`, ask the user to approve exactly `amountIn`** for that router — never an unlimited amount. Hand it over like the swap in rule 22: `to` = the token, `data` = `approve(<router>, <amountIn>)`, `value` = `0`. If the approval reverts on a token that already has a non-zero allowance, approve `0` first, then the amount.
18. **After the approval is confirmed on-chain, call `/swap` again** and repeat checks 13 and 14. A plain simulation before the approval always reverts; if your RPC supports `eth_call` state overrides, you may override the allowance to dry-run before asking for the approval.

### Simulate

19. **Simulate the swap with `eth_call`** from the user's address to `tx.router`, with `tx.data`, and `value = amountIn` for native-token input (otherwise `0`).
20. **The call returns the output amount as one 32-byte word. Check it is at least `minAmountOut`.**
21. **If it reverts, do not send.**

| Revert                                                                    | Likely cause                                                                                                            |
| ------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `TransferHelper: TRANSFER_FROM_FAILED`                                    | Missing approval, or the wallet holds less than `amountIn` — check `balanceOf` and `allowance`                          |
| `insufficient funds for gas * price + value` (an RPC error, not a revert) | The wallet holds less HYPE than the value plus gas — tell the user; do not retry                                        |
| `TransferHelper: TRANSFER_FAILED`                                         | The output token refused the transfer to `receiver` — check the receiver; do not retry blindly                          |
| `TransferHelper: ETH_TRANSFER_FAILED`                                     | `receiver` cannot accept native HYPE (for example a contract) — do not retry; ask for another receiver or swap to WHYPE |
| Anything else                                                             | The route moved — call `/swap` again and re-simulate once; if it still reverts, report the message to the user          |

Match on the message text: reverts can arrive wrapped, as `callBytes failed: Error(…)`.

### Sign and confirm

22. **Do not sign yourself.** Ask how the user signs, then give the transaction in that form: a command for their own terminal (for example `cast send` with `--ledger` or `--interactive`), or `to`, `data`, `value` (in wei) and chain ID for a wallet that accepts a custom transaction. Name the chain and its ID and ask the user to check their wallet is on it: the standard router has the same address on both chains, so a wallet on the wrong chain would send the swap there. Never ask for a password or key to sign on their behalf.
23. **Check the receipt** for the transaction hash the user gives you, with a time limit. Status `1` means the swap went through: give the explorer link (`<explorer>/tx/<hash>`). Status `0` means it reverted on-chain — nothing was swapped, only gas was spent. Quote again before retrying.

### API errors

| Body                                                                                      | Status | What to do                                                                               |
| ----------------------------------------------------------------------------------------- | ------ | ---------------------------------------------------------------------------------------- |
| `{"error": "Bad request. Reason: minAmountOut is above the quoted output less slippage"}` | `400`  | The price moved against the user — see rule 14                                           |
| `{"error": "Bad request. Reason: …"}` or any other message                                | `400`  | Read the reason, fix the parameter, retry                                                |
| `{"errors": [{"field": "...", "message": "..."}]}`                                        | `400`  | A parameter is malformed (e.g. a non-numeric `amountIn`) — fix that field                |
| `{"error": "Key: '…' Error:Field validation for '…' failed on the 'required' tag"}`       | `400`  | A required parameter is missing (e.g. `receiver` on `/swap`)                             |
| `{"error": "token not found"}`                                                            | `404`  | The token is not on this chain — check the address and the chain                         |
| `{"error": "no path found"}`                                                              | `404`  | No route for this pair and amount — suggest a smaller amount or a different pair         |
| `{"error": "rate limit exceeded"}`                                                        | `429`  | Wait and retry with an increasing delay (250 ms, 500 ms, 1 s, …); stop after a few tries |
| anything                                                                                  | `5xx`  | A fault on our side — retry once after a few seconds, then report it                     |

Public RPCs are rate-limited too: the HyperEVM one starts refusing after a few calls per second. Space reads about a second apart, or use the user's own RPC.

### Reference

* Full parameters and responses: [DEX Aggregator API](https://docs.hyperflow.fun/developers/dex-aggregator.md)
* Router addresses: [Smart Contracts](https://docs.hyperflow.fun/developers/smart-contracts.md)