Solana → EVM swap
Move SOL or USDC from Solana to an EVM chain — sign the base64 VersionedTransaction with a Solana wallet, send it, report it and track the order.
To swap SOL on Solana into USDC on an EVM chain with LayerHop, request a quote with srcChain=solana, build the transaction (a base64 Solana VersionedTransaction), have the user's Solana wallet sign it, send it, report the signature and track the order. Solana-source routes are served by deBridge and LI.FI today; Relay quotes EVM-source routes only, and Mayan is available on request.
Which providers route from Solana to EVM?#
| Provider | Solana → EVM | Notes |
|---|---|---|
| deBridge | Yes | Cross-chain only. |
| LI.FI | Yes | Bridges and swaps across many chains. |
| Relay | No | Relay serves EVM → Solana, not Solana-source routes. |
| Mayan | Available on request | Built, held back in production. |
The example sends 2 SOL (9 decimals, amount: "2000000000") to USDC on Arbitrum.
1. Get a quote#
const { best: quote } = await lh.quote({
srcChain: "solana",
srcToken: "SOL", // native SOL, the wrapped-SOL mint So111…112
amount: "2000000000", // 2 SOL in base units
dstChain: "arbitrum",
dstToken: "USDC",
sender: solanaAddress,
recipient: evmAddress,
});2. Build and sign the transaction#
The source is Solana, so you get an SvmTx whose serializedTx is a base64 VersionedTransaction.
import { useConnection, useWallet } from "@solana/wallet-adapter-react";
import { VersionedTransaction } from "@solana/web3.js";
const { connection } = useConnection();
const { signTransaction } = useWallet();
const tx = await lh.buildTx(quote.quoteId);
if (tx.vm !== "svm") throw new Error("expected a Solana transaction");
const unsigned = VersionedTransaction.deserialize(base64ToBytes(tx.serializedTx));
const signed = await signTransaction!(unsigned);Browser-safe base64 helpers (no Buffer needed):
const base64ToBytes = (b64: string) => Uint8Array.from(atob(b64), (c) => c.charCodeAt(0));
const bytesToBase64 = (bytes: Uint8Array) => btoa(String.fromCharCode(...bytes));Note
The transaction already contains a recent blockhash chosen by the provider. Sign and send it promptly: Solana blockhashes expire after roughly a minute, and some providers expect the order on chain within about 30 seconds of building.
3. Send and report the signature#
If tx.submitViaApi is true, send the signed bytes through LayerHop; the API reports the order for you. Otherwise broadcast them yourself and then report the signature.
let signature: string;
if (tx.submitViaApi) {
signature = await lh.submit(quote.quoteId, bytesToBase64(signed.serialize())); // POST /v1/orders/submit
} else {
signature = await connection.sendRawTransaction(signed.serialize(), { maxRetries: 3 });
await lh.reportSubmitted(quote.quoteId, signature); // POST /v1/orders/{quoteId}/submitted
}
await connection.confirmTransaction(signature, "confirmed");See The submitViaApi flow for why some transactions go through the API.
4. Track the order#
for await (const s of lh.watch(quote.provider, signature)) console.log(s.state);For deBridge and LI.FI the order id is the Solana transaction signature. With an API key, webhooks tell you when the order is filled, refunded or failed.
What are the common issues?#
- Not enough SOL for fees and rent. Solana-source swaps need some SOL on top of the amount for the network fee and any token accounts the transaction creates. Keep a small buffer when the user sells SOL.
Blockhash not foundor expired. Too much time passed between build and send. Build again, and re-quote if the quote expired (QUOTE_EXPIRED).- The wallet's simulation fails. Usually the price moved beyond
slippageBps. Re-quote, or runPOST /v1/simulateto see the error before the wallet prompt.
Last updated