EOA Swap example

EOA Swap flow

A standard wallet swap (MetaMask, WalletConnect, or any EOA signer) in six steps:

  1. Fetch supported networks and tokens

  2. Find a route

  3. Approve token spending (ERC-20 only)

  4. Send swap transaction

  5. Extract requestId from receipt

  6. Poll for completion

Step 1: Get Networks and Tokens

GET /networks

Returns an object keyed by network name. Each entry contains the chain configuration and supported tokens.

{
  "sepolia": {
    "name": "sepolia",
    "chainId": 11155111,
    "router": "0x...",
    "tokens": [
      {
        "chainId": 11155111,
        "address": "0x...",
        "name": "USD Coin",
        "symbol": "USDC",
        "decimals": 6,
        "tags": ["erc20", "stable"],
        "permit": false
      }
    ]
  }
}

Use chainId and token address values from this response when building a scan request.

Step 2: Find a Route

Request body:

Field
Type
Required
Description

from

string

Yes

Sender address

recipient

string

No

Recipient address (defaults to sender)

params.tokenIn

string

Yes

Input token address

params.amountIn

string

Yes

Amount in smallest token units

params.chainIdIn

number

Yes

Source chain ID

params.tokenOut

string

Yes

Output token address

params.chainIdOut

number

Yes

Destination chain ID

slippage

number

Yes

Slippage tolerance in percent

feeShareBps

number

No

Partner fee in basis points (100 = 1%)

providers

string[]

No

Filter by provider: "cross-curve", "rubic", "bungee"

The response is NDJSON — each line is a separate JSON object:

Success line:

Error line (route could not be evaluated):

Collect the simulation objects from success lines. Routes arrive in arbitrary order, so sort by amountOut descending to find the best route and pass it to the next step.

You can also use POST /routing/scan which returns all routes as a single JSON array. The request body is the same. Each array item has the same shape as the simulation object above.

Step 3: Build the Transaction

Request body:

Field
Type
Required
Description

from

string

Yes

Sender address

recipient

string

Yes

Recipient address

routing

object

Yes

The simulation object from /routing/scan/stream (or array item from /routing/scan)

buildCalldata

boolean

No

When true, returns encoded calldata ready to send

Pass the entire route object as routing. Do not modify or cherry-pick fields from it.

Response when buildCalldata is true:

Response when buildCalldata is false or omitted:

Step 3: Approve Token Spending (ERC-20 only)

If the input token is an ERC-20 (not the native token), approve the router contract to spend your tokens before sending the swap transaction. The router address is the to field from the /tx/create response.

Skip this step if the input token is the chain's native token (ETH, MATIC, etc.) — native tokens do not require approval.

For ERC-4337 and EIP-7702 wallets, the approval is already included in the calls[] array returned by /tx/create. This step applies only to EOA transactions.

Step 4: Send Swap Transaction

Send the transaction on-chain using your wallet or signer.

Step 5: Extract requestId

After the transaction is confirmed, extract the requestId from the ComplexOpProcessed event in the receipt:

Step 6: Poll for Completion

Poll GET /transaction/{requestId} until the status reaches a final state.

See Transaction Tracking for response format and polling recommendations.

Full Example (JavaScript + ethers.js)

Full Example (TypeScript + viem)


Last updated