Same-chain swaps
Swap tokens on one chain — Jupiter on Solana; 0x, KyberSwap, Relay and LI.FI on EVM — and confirm the result on chain.
To swap two tokens on the same chain with LayerHop, call GET /v1/quote with the same srcChain and dstChain, build and sign the best route, then confirm the transaction on chain. The calls are the same as for bridging; only tracking differs, because same-chain swaps settle inside one transaction.
Which providers serve same-chain swaps?#
| Chain family | Providers | Notes |
|---|---|---|
| Solana | Jupiter, LI.FI | Jupiter is Solana same-chain only. |
| EVM | 0x, KyberSwap, Relay, LI.FI | 0x and KyberSwap are EVM same-chain only. |
Every provider that can serve the pair is asked in parallel and ranked by what the user receives. See Providers & ranking.
1. Get a quote#
Solana example, 25 USDC to SOL:
const { best } = await lh.quote({
srcChain: "solana", srcToken: "USDC", amount: "25000000", // 25 USDC
dstChain: "solana", dstToken: "SOL",
sender: solanaAddress, recipient: solanaAddress,
});EVM example, 0.5 ETH to USDC on Arbitrum:
const { best } = await lh.quote({
srcChain: "arbitrum", srcToken: "ETH", amount: "500000000000000000", // 0.5 ETH
dstChain: "arbitrum", dstToken: "USDC",
sender: evmAddress, recipient: evmAddress,
});2. Build the transaction#
const tx = await lh.buildTx(best.quoteId);- EVM: selling the native coin puts the amount in
valueand needs no approval. Selling an ERC-20 returns anapprovalto send first. - Solana (Jupiter): most Jupiter routes come back as a normal transaction for the wallet to broadcast. When no LayerHop fee account fits the pair, Jupiter's fallback path returns
submitViaApi: true, and you send the signed transaction throughPOST /v1/orders/submitinstead.
3. Sign, send and report#
// EVM: send with the wallet, then report the hash
const hash = await wallet.sendTransaction({ account, to: tx.to, data: tx.data, value: BigInt(tx.value) });
await lh.reportSubmitted(best.quoteId, hash);
// Solana
const signed = await signTransaction(VersionedTransaction.deserialize(base64ToBytes(tx.serializedTx)));
const signature = tx.submitViaApi
? await lh.submit(best.quoteId, bytesToBase64(signed.serialize())) // reported automatically
: await connection.sendRawTransaction(signed.serialize());
if (!tx.submitViaApi) await lh.reportSubmitted(best.quoteId, signature);Reporting the hash lets LayerHop track the order and send webhooks.
4. Confirm on chain#
Same-chain providers settle inside the transaction, so GET /v1/orders/jupiter/{id}, /zerox/{id} and /kyberswap/{id} always return state: "unknown". Confirm the transaction yourself:
// EVM
const receipt = await pub.waitForTransactionReceipt({ hash });
const ok = receipt.status === "success";
// Solana
const { value } = await connection.confirmTransaction(signature, "confirmed");
const ok = value.err === null;When you reported the hash, LayerHop's worker does the same check (receipt or signature status) and marks the order filled or failed, which fires order.filled or order.failed. Relay and LI.FI same-chain swaps can also be tracked through GET /v1/orders/{provider}/{id} like cross-chain ones.
What fee applies to a same-chain swap?#
The same channel fee as any other swap: 0.10% for the API, 0.15% for the web app and widget, 0.45% for the Telegram bot, plus any partner fee. The fee actually applied is in fees.ourFeeBps on every quote. See Fees & channels.
Last updated