Skip to content
LayerHop

LayerHop for developers · Cross-chain swap API

A cross-chain swap API: quote, build, sign, track

The LayerHop API gets you from a swap request to a tracked order in four calls. GET /v1/quote asks every route provider that serves the pair and returns ranked quotes, POST /v1/orders builds the unsigned transaction for the one you pick, your user's wallet signs and sends it, and POST /v1/orders/{quoteId}/submitted plus GET /v1/orders/{provider}/{id} track it. It covers 71 chains, EVM and Solana, and never holds keys.

Base URL
https://api.layerhop.com/v1
curl https://api.layerhop.com/v1/health   # no account needed to try it

How to make a swap with the API

  1. 1

    Request quotes

    GET /v1/quote with srcChain, srcToken, amount (integer base units), dstChain, dstToken, sender and recipient. The sender and recipient must be addresses of the source and destination chains' families (0x for EVM, base58 for Solana). The response has best, quotes (every route, best first) and errors (providers that could not quote).

  2. 2

    Build the transaction

    POST /v1/orders with the quoteId of the quote the user picks, before expiresAt. The answer is an unsigned EVM transaction (with an ERC-20 approval to send first when needed) or a Solana serialized transaction.

  3. 3

    Have the user's wallet sign and send it

    For an EVM chain, send tx.approval first when it is present, then the main transaction (to, data, value) on tx.chainId. For Solana, sign the base64 VersionedTransaction; when submitViaApi is true, send the signed bytes through LayerHop instead of an RPC node.

  4. 4

    Report the transaction

    POST /v1/orders/{quoteId}/submitted with the transaction hash, so LayerHop tracks the order and your webhooks fire.

  5. 5

    Track the order

    GET /v1/orders/{provider}/{id} with the source transaction hash returns pending, filled, refunded, failed or dropped. Webhooks and a Server-Sent Events stream are available for push updates.

Code

Copy, then replace the addresses and the key.

The four calls with curl
# Add -H "x-api-key: lh_live_..." to any call when you have a key.
# 1. Quote: 100 USDC on Base -> SOL on Solana (amounts are base-unit strings)
curl "https://api.layerhop.com/v1/quote?srcChain=base&srcToken=USDC&amount=100000000&dstChain=solana&dstToken=SOL&sender=0x1111111111111111111111111111111111111111&recipient=9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM"
# -> { "best": { "quoteId": "q_...", "provider": "relay", "dstAmount": "...", "dstAmountMin": "...",
#      "estimatedSeconds": ..., "fees": { "ourFeeBps": 10, ... }, "expiresAt": ... }, "quotes": [...], "errors": [] }

# 2. Build the unsigned transaction for the quote you pick, before it expires
curl -X POST https://api.layerhop.com/v1/orders \
  -H "content-type: application/json" \
  -d '{"quoteId":"q_..."}'
# -> { "quoteId": "q_...", "provider": "relay", "tx": { "vm": "evm", "chainId": 8453, "to": "0x...", "data": "0x...", "value": "0", "approval": {...} } }

# 3. After the user's wallet broadcast it, tell LayerHop which transaction belongs to the quote
curl -X POST https://api.layerhop.com/v1/orders/q_.../submitted \
  -H "content-type: application/json" \
  -d '{"txHash":"0x..."}'

# 4. Track it: cross-chain providers take the SOURCE transaction hash
curl https://api.layerhop.com/v1/orders/relay/0x...
# -> { "provider": "relay", "id": "0x...", "state": "pending" | "filled" | "refunded" | "failed" | "unknown" | "dropped", "dstTxHash": "..." }
The same flow with the TypeScript SDK
import { LayerHop } from "@layerhop/sdk";

const lh = new LayerHop({
  apiKey: process.env.LAYERHOP_API_KEY, // optional, sent as x-api-key
  channel: "api",                       // fee channel; baseUrl defaults to https://api.layerhop.com
});

// 1. Quote: 100 USDC on Base -> SOL on Solana (amounts are base-unit strings)
const { best, quotes, errors } = await lh.quote({
  srcChain: "base", srcToken: "USDC", amount: "100000000",
  dstChain: "solana", dstToken: "SOL",
  sender: "0x1111111111111111111111111111111111111111",      // pays on Base
  recipient: "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM", // receives on Solana
  slippageBps: 50,
});
console.log(best.provider, best.dstAmount, best.dstAmountMin, best.estimatedSeconds);
console.log("LayerHop fee (bps):", best.fees.ourFeeBps);

// 2. Build the unsigned transaction (right after the user confirms)
const tx = await lh.buildTx(best.quoteId);

// 3. Optional dry run before asking for a signature
await lh.simulate(best.quoteId);

// 4. The wallet signs and sends tx (see the quickstart for viem and Solana), then:
await lh.reportSubmitted(best.quoteId, srcTxHash);

// 5. Track until the order is final
for await (const status of lh.watch(best.provider, srcTxHash)) {
  console.log(status.state, status.dstTxHash ?? ""); // pending -> filled / refunded / failed
}

What works today, and what doesn't

So you know before you build.

Works today

  • Quotes from every provider that serves the pair in one call, best first, with each provider that could not quote listed instead of hidden
  • Exact-output quotes (receive an exact amount), gas on arrival, gasless same-chain swaps and destination calls (beta), each documented in the guides
  • Signed webhooks for order events, live order status over Server-Sent Events, and test mode keys (lh_test_) with simulated orders
  • A fee that is reported on every quote and an optional partner fee on top

Good to know

  • It never signs or broadcasts: the user's wallet does
  • Quotes expire (30 to 60 seconds after they are made, by provider); build the order right after the user confirms
  • Same-chain swaps report unknown from the status endpoint, because there is nothing to track off-chain: confirm them on chain or use webhooks
  • Providers are mainnet only; there is no testnet. Use test mode or the local mock API for development

Questions

Do I need an API key?

Not to try it: requests without a key work under a per-IP rate limit. For production, sign in to the dashboard with a wallet and create a key (lh_live_…, sent in the x-api-key header). A key gets its own rate limit, shows your usage and logs, and lets your orders trigger webhooks. lh_test_ keys give sandbox quotes and simulated orders.

What does it cost?

LayerHop's fee on a trade made through the API channel is 0.10% of the input amount, reported on every quote as fees.ourFeeBps next to the provider's fees and gas. Partners can add their own fee on top.

Does it hold keys or sign transactions?

No. It returns unsigned transactions and your own wallet library (viem, ethers, web3.py, go-ethereum, alloy, a Solana wallet, a KMS) signs and broadcasts them. LayerHop never holds funds or keys.

What are amounts measured in?

Integer strings in the token's base units, never floats: 100 USDC (6 decimals) is "100000000".

Is there an OpenAPI spec?

Yes. The OpenAPI 3.1 file is the source of truth for the reference and the SDKs, and there is a Postman collection and an API playground in the docs.