@layerhop/sdk

Typed TypeScript client for the LayerHop API: best-price cross-chain and
same-chain swaps across EVM chains and Solana through one non-custodial API.
- Zero runtime dependencies. Uses the global
fetch; works in Node 18+, browsers, Deno, Bun and edge runtimes.
- ESM + CommonJS builds with bundled type definitions.
- Never holds keys. It fetches quotes and builds unsigned transactions; your wallet signs.
Install
npm install @layerhop/sdk
Quickstart
Amounts are always integer strings in base units (100 USDC = "100000000"), never floats.
import { LayerHop, LayerHopApiError } from "@layerhop/sdk";
const lh = new LayerHop({ apiKey: process.env.LAYERHOP_API_KEY, integrator: "myapp" });
const { best } = await lh.quote({
srcChain: "base", srcToken: "USDC", amount: "100000000",
dstChain: "solana", dstToken: "SOL",
sender: "0xYourEvmAddress", recipient: "YourSolanaAddress",
});
const tx = await lh.buildTx(best.quoteId);
Errors are thrown as LayerHopApiError with a stable code (see the
error catalog):
try {
await lh.buildTx(quoteId);
} catch (e) {
if (e instanceof LayerHopApiError && e.code === "QUOTE_EXPIRED") {
}
}
API
quote(params) | GET /v1/quote | Every successful quote, best for the user first. |
buildTx(quoteId) | POST /v1/orders | The unsigned transaction for a quote (EvmTx or SvmTx). |
submit(quoteId, signedTx) | POST /v1/orders/submit | Solana txs with submitViaApi: send the signed tx through LayerHop. |
reportSubmitted(quoteId, txHash) | POST /v1/orders/{quoteId}/submitted | Tell LayerHop the tx was broadcast. |
simulate(quoteId) | POST /v1/simulate | Dry-run the tx (EVM eth_call + gas, Solana simulateTransaction). |
listOrders(params) | GET /v1/orders | Orders from or to an address, newest first. |
status(provider, id) | GET /v1/orders/{provider}/{id} | Order status. |
watch(provider, id, opts?) | polls status | Async generator yielding each state change until final. |
Options for new LayerHop(options): baseUrl (default https://api.layerhop.com), apiKey,
channel, integrator, integratorFeeBps, fetch.
The package also exports the chain and token registry (CHAINS, getChain, TOKENS, findToken,
SOLANA_CHAIN_ID, EVM_NATIVE, SOL_NATIVE) and all request/response types.
Full reference: https://docs.layerhop.com/sdk.
Related packages
License
MIT