BETA

ChainHilt is in beta. Use at your own discretion.

chainhilt

Swap

Swap tokens from your agent

ChainHilt asks every enabled DEX aggregator for a quote, picks the best one, and returns the approval and swap transactions for your wallet to sign. Quotes are free; preparing the transactions costs $0.01.

How a swap runs

  1. Quote (free, optional)

    POST /api/v1/swap/quote returns every connector's quote, best first. Execute quotes again on its own, so this step is only for showing prices before committing.

  2. Authorize

    Call the wallet's authorize_request with the exact execute request: method, URL and JSON body.

  3. Execute ($0.01)

    Send the request through your x402 client (AgentCash fetch) with the header it returned. takerAddress is your wallet's address.

    POST https://chainhilt.ai/api/v1/swap/execute
    X-ChainHilt-Authorization: <from authorize_request>
    
    {
      "chainId": 8453,
      "sellToken": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
      "buyToken": "0x4200000000000000000000000000000000000006",
      "sellAmount": "1000000",
      "takerAddress": "0xE4934BB19E0B97109033dBfDcCc6957E32F9Cc60",
      "slippageBps": 100
    }

    The response holds ordered actions: up to two approvals, then the swap.

  4. Sign and send

    Pass the actions' nonce and hashes to process_action. The wallet sends them in order and waits for each one to confirm before the next.

Before you sign

  • Swaps are not reversible. Confirm the tokens, the amount sold and the minimum received with the user.
  • sellAmount is in the token's smallest unit. For the chain's native token, use 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE or the zero address.
  • slippageBps is capped at 5000 (50%). Thin pools need more tolerance than deep ones: pick what the pool needs and confirm it with the user.
  • Approvals cover exactly the amount sold, never more. When the existing allowance already covers it, no approval is sent.
  • Quotes already account for ChainHilt's fee where a connector supports one.
  • GET /api/v1/swap/connectors lists the enabled aggregators. Pass excludedConnectors to leave some out.

Endpoints

Swap endpoints and their prices
EndpointPriceWhat it does
POST /api/v1/swap/quoteFreeGet ranked swap quotes
POST /api/v1/swap/execute$0.01Select the best available swap quote and return ordered unsigned transaction actions.

Next